I Hacked Another File Upload Website

Поділитися
Вставка
  • Опубліковано 31 гру 2024

КОМЕНТАРІ • 144

  • @reikooters
    @reikooters Рік тому +140

    This is why you don't trust filenames of uploaded files. Instead you should generate your own local filename when storing to disk - a string of random characters or at least a guid/uuid. Then you can store the local filename and the uploader's filename (without path) to a database to tie them together, and just use the uploader's filename for display purposes and in the Content-Disposition header when allowing the user to download the file again. This is basics. It's just like how there are particular file formats which you never store on the server as the same file which was uploaded, such as image files and PDFs - you load/parse them and then resave them in order to sanitize them.

    • @foxbeans1509
      @foxbeans1509 11 місяців тому +6

      You don't even need to write them to the disk, you can just open a pipe to the stdin/stdout of dos2unix and read it that way.

    • @twirre
      @twirre 11 місяців тому +12

      @@foxbeans1509 In this case you don't even have to make a trip to the server. This could totally be done client side.

    • @okie9025
      @okie9025 11 місяців тому +1

      This works until you consider something like image backup software, where conserving the file names and the actual folder structure is more important. If the user wants to download all of the images in the exact same way they uploaded them, you don't need to take a round-trip to the database to fetch the original file name for potentially 10s of thousands of images - you just send the images as-is.

    • @v12alpine
      @v12alpine 10 місяців тому

      Then they can just use SQL injection instead assuming there's still no sanitation or escaping.

    • @darekmistrz4364
      @darekmistrz4364 10 місяців тому

      @@twirreHow do you want to run Linux binary on the browser?

  • @huskyhacks
    @huskyhacks Рік тому +49

    *stands out of chair and throws roses at computer screen*
    BRAVISSIMO SIGNORE

  • @fearlessmailbox7347
    @fearlessmailbox7347 Рік тому +65

    Hey man, I'm an automation engineer and I mainly work with PLC's and other industrial hardware. Just wanted to share videos like these motivate me to practice more on the real software wide. Thx my guy, have a good one

    • @Slangs
      @Slangs Рік тому +1

      I am the exact opposite lol, any idea where to start if I don't have engineering background?

    • @norliegh
      @norliegh 11 місяців тому

      ​​​@@Slangsget a computer, open a terminal & start typing. if you don't understand something, google it with a "what/why". almost all commands have manuals so do "man " in the terminal. this way you can read the manual for that command. that's it.

    • @OhertRasmus
      @OhertRasmus 11 місяців тому

      ​​@@SlangsI'd recommend just googling what certain code languages are capable of doing. Search projects other people have done, and see what languages they've used.
      If you're interested in making diy robots/machines, then I'd recommend Python (or ROS) for the raspberry pi and C++/C for the Arduino.
      I've studied automation for 5 years, and Python is my daily driver. Python is a good and easy starting point for automation type tasks.

    • @fearlessmailbox7347
      @fearlessmailbox7347 11 місяців тому

      @@Slangs I'm not entirely sure. Most hardware lies behind very expensive licenses, so it's a bit harsh to get into on your own

  • @scwfan08
    @scwfan08 Рік тому +66

    This is so out of my abilities but I kinda understood what he did. Amazing teacher.

    • @trustedsecurity6039
      @trustedsecurity6039 Рік тому +2

      It is simple command injection, he just used python to make the job and that make it totally unclear for beginners.

  • @kevinwilson7213
    @kevinwilson7213 9 місяців тому

    Dude! Such a cool attack. Also, pretty amazing that SNYK finds the -debug mode enabled vuln AND command injection vuln (I guess they are linked, but still... cool). I also loved the panic that set in when dosbox was blasting your screen, hahaha (meaning it's nice to know I'm not the only one who panics :)

  • @kleinesfilmroellchen
    @kleinesfilmroellchen 11 місяців тому +2

    7:49 filenames with spaces can add arbitrary shell commands, and filenames can contain dots so they may be written to outside the upload folder.

    • @vnc.t
      @vnc.t 10 місяців тому

      yes, i was thinking you just set filename to " || "

  • @darekmistrz4364
    @darekmistrz4364 10 місяців тому

    This is a great example why security can have many levels. You can still use this code "securely" if you host it on ephemeral environment where access like this isn't a dealbreaker. If this would be hosted on AWS Lambda (or Lambda+S3) with proper timeouts then attackers are wasting their time. I'm not a cloud advocate, I don't even like AWS. You can use whatever function/lambda/serverless platform that you want to. But for a web application like this, where file access from public internet is possible, it's a good practice to keep it contained in a safe sandbox. If you would want, you can even set it up so that each session is handled by different docker container with a lifespan of 1 minute or something similar. It's a bit more advanced setup but still doable with mostly opensource tools and without "serverless" bs

  • @GavinFraser
    @GavinFraser Рік тому +4

    Congrats on 1 Million 🍾

  • @donkaos501
    @donkaos501 Рік тому +6

    16:03 brain buffer overflow

  • @attilao
    @attilao 11 місяців тому +3

    To be fair, this is a pretty blatant vulnerability, even the most basic code review should catch it. Even LLM based code reviews. That said, nice video, well done.

    • @darekmistrz4364
      @darekmistrz4364 10 місяців тому

      Also this should be running on ephemeral environment where access like this isn't a dealbreaker. If this would be hosted on AWS Lambda (or Lambda+S3) with proper timeouts then attackers are wasting their time.

  • @sylvainc8146
    @sylvainc8146 Рік тому +7

    This is a completely crazy vulnerability. 🤣
    I challenge you to do the same on a Django environment !

  • @roadw2k
    @roadw2k Рік тому +4

    Once you got into the reverse shell, and that you had sudo access, wouldn't you be able to do the "sudo cat /root/flag.txt"?

    • @Sk-oh7rv
      @Sk-oh7rv Рік тому +8

      When using sudo -l command, you list the possible things that you can run (along with info such as if you need to put the password of the user, etc). In this case, you could only use sudo to execute /usr/bin/dosbox, so you can't do "sudo cat". That's why you have to find a way of escalating your privileges within the context of using dosbox, since it maintains the root privileges while the program is running.

  • @Euronauts
    @Euronauts Рік тому +3

    @25:49 I don't get how it goes to writing files, shouldn't the output filename become the '/app/app.py' value so it reads the source from bad_app and writes that to the app's source code file? Am I missing something?

    • @Halorocker101
      @Halorocker101 Рік тому +3

      Yea I don't understand why it didn't just write bad_app to output.txt.

    • @Euronauts
      @Euronauts Рік тому +1

      @@Halorocker101 So I watched it again and I missed at 5:55 the function that saves the file. So he only uses the output.txt file to get to the right path but actually the source file gets already saved when you upload it. At 8:46 he points out that the sanitized filename (filename var) is never used, that's where the vulnerability starts. Guess I should be less tired when watching John's video haha

    • @MP3Martin
      @MP3Martin Рік тому

      ​​@@Euronautswait so by uploading a file named "/temp/test.txt" with the content "hello" will create a file in "/temp/" called "test.txt" with content "hello"?
      if not then i understand everything except the write_file function

    • @Euronauts
      @Euronauts Рік тому +1

      yes indeed. Just by uploading a file you can escape the upload directory because the function never sanitizes the filename,@@MP3Martin

    • @MP3Martin
      @MP3Martin Рік тому

      @@Euronauts thanks

  • @1vader
    @1vader 11 місяців тому +2

    Not sure if that was just an accident but you don't have to declare global variables with "global" to read them in a function in Python and I'd say it's pretty bad style to do it. You only need to do that to write to them since Python will assume you're trying to declare a new local variable otherwise.

  • @Hackerjedi
    @Hackerjedi Рік тому +16

    amazing content as ever love your little python exploits

  • @LadyLatency
    @LadyLatency Рік тому +2

    gr8 content, slight note i dont think ive ever heard someone pronounce /etc other than 'et-see'

  • @nasimfaheemalquadir
    @nasimfaheemalquadir Рік тому +1

    0:22 so thats why all my text files end in an empty line that I cannot figure out how to rid of

  • @dennisk4813
    @dennisk4813 Рік тому +9

    Great Video 🎉 I‘m a little bit confused about the ordering of the entries in files list within the write_file function. I thought first Parameter after the -n -f flags is input file, thus I would have swapped the ordering of entries in files list. But maybe I overlook something😅

    • @Slangs
      @Slangs Рік тому +2

      me too, I am still very confused about this, no idea what happened there

    • @Ebiko
      @Ebiko Рік тому

      Could you add a timestamp ?
      Cause the order is correct from my quick glimpse.
      First input, then output parameters
      The file list looks correct in ~ 17:00

    • @dennisk4813
      @dennisk4813 Рік тому

      @@EbikoYeah sure! I meant the files list at 25:00 The list at 17:00 looks also good to me 😊

    • @1vader
      @1vader 11 місяців тому

      The upload doesn't have anything to do with dos2unix, it's just the functionality of the app. You upload a file before it's passed to dos2unix. It's definitely pretty confusing in the video, you don't need the -f or -n or anything like that for uploading.

    • @rbalfanz
      @rbalfanz 11 місяців тому

      Same. Will watch that section a third time now after reading these comments to understand what I’m missing.

  • @QWERTIOX
    @QWERTIOX Рік тому +3

    Moral of the story, don't run shell commands with user provided data. And is it really needed to use that command to convert the file? Like you could done that with simple replace all or even don't use uploading and just convert this files in place using js in users browser

    • @WolfrostWasTaken
      @WolfrostWasTaken Рік тому +2

      JS in place is underrated. No need to call any server, the app will even work offline and it will be faster.

    • @arjix8738
      @arjix8738 11 місяців тому

      ​@@WolfrostWasTakenit is not underrated, it is actually overrated but for the wrong reasons lol

    • @darekmistrz4364
      @darekmistrz4364 10 місяців тому

      @@WolfrostWasTaken Great! Please share your javascript code that has no problem running any linux binary. I have so many of this converting web applications that it would save me a lot of hassle with ffmpeg and all sorts of custom c++ binaries

  • @debarghyamaitra
    @debarghyamaitra Рік тому +3

    Best explanation on the internet!

  • @vargnaar
    @vargnaar Рік тому +2

    I'm sorry Orange flavoured John but all that amazing information went right through me because I couldn't stop noticing how you're gripping the mic while it is on a very nice armature. 👀

  • @0x42NaN
    @0x42NaN 11 місяців тому

    even before you asked I thought about unsanitized filename inputs. path traversal attacks maybe. maybe reverse shell with a really funny spoofed POST

  • @AhmadAli-sd5mk
    @AhmadAli-sd5mk Рік тому +6

    we need a full course on Udemy :)

  • @Slangs
    @Slangs Рік тому +1

    I am a bit confused, shouldn't the script write the input to the output and that's how you read /etc/passwd? how did you replace /etc/passwd and it just wrote to it?

    • @nothanks39
      @nothanks39 Рік тому

      in app,py it tries to save each file to upload_folder/filename. i think that when doing read_file("/etc/passwd"), app,py fails to save to /etc/passwd, then ends up doing dos2unix -f -n /etc/passwd output.txt, which writes to output.txt the unchanged passwd file. when write_file("/app/app,py, ...") happens, app,py overwrites itself when it saves all the files to upload_folder/filename. app,py can write to app,py because the crlf user (who is currently running app,py) has owns app,py, but can't write to /etc/passwd since that needs sudo/root

  • @jakelancaster5889
    @jakelancaster5889 Рік тому +1

    Why did you have to do global url in the function wouldn't it be automatically global scope being declared already above?

    • @1vader
      @1vader 11 місяців тому

      Yeah, there was no reason he had to do that, I think he just got a bit confused.

  • @tutacat
    @tutacat 10 місяців тому

    CR is just called carriage return, not carriage return, line feed (CRLF)

  • @kageofkonoha
    @kageofkonoha 11 місяців тому +1

    Excellent teaching video. Btw I'm speaking with over 3 decades being in the field the - in the ASCII world is dash; ; . Tack is a military used term. Basically used for the same thing but as people left the military in the field it was taught to others and that's how it got introduced into the field but never entered into the ASCII table description. Look up an ASCII table. It will by hyphen-minus.

  • @razzawazza
    @razzawazza Рік тому

    Damn 1m subs congrats mate.

  • @tutacat
    @tutacat 10 місяців тому

    Man will never move the webcam view.

  • @LordMarcus
    @LordMarcus Рік тому +5

    If you're in a position to know you need a CRLF convertor, aren't you probably in a position to know either how to do it or how to look up how to do it with whatever editor you're using?

    • @Zer-ei4co
      @Zer-ei4co Рік тому +2

      Good point lol. I assume he just used that site for demonstration purposes because it's simple.

  • @landless-wind
    @landless-wind Рік тому +3

    thanks
    with love from:
    PCA - Philippines

  • @SamuelViagus
    @SamuelViagus 11 місяців тому

    This man needs a raise!

  • @Reflexes18
    @Reflexes18 Рік тому +1

    In the first min I was thinking.
    Wait.. how did you copy and paste a file from your host to your virtual machine and how did you zoom in with the terminal?

    • @aeghohloechu5022
      @aeghohloechu5022 Рік тому

      If you have the vm guest extensions set up properly you can actually copypaste between host and vm.
      And Ctrl+"+" for zooming in

    • @scary34
      @scary34 Рік тому

      Ctrl + scroll down to zoom

  • @jimdiroffii
    @jimdiroffii Рік тому +1

    My guess is the vuln is in the filename parsing.

  • @T3SS3R4ACT
    @T3SS3R4ACT 11 місяців тому

    I love when you try to get privilege escalation you accidentally open a portal into the 5th dimension

  • @keithharvey633
    @keithharvey633 Рік тому +2

    Why would a website like that even need a backend haha , should just do all of the transformation locally

    • @upsxace
      @upsxace 11 місяців тому

      So you can keep people's data 🤫

  • @ChrisBradel
    @ChrisBradel 11 місяців тому

    Great video but the grabbing of an already mounted mic gives me a weird anxiety. 😅

  • @highfiveshighfives4980
    @highfiveshighfives4980 Рік тому

    Someone’s got to stop him

  • @charlesmarseille123
    @charlesmarseille123 Рік тому

    The standard voice is back!!!! ALRIGHT :)

  • @abitterberry2149
    @abitterberry2149 Рік тому +15

    Great challenge! I can understand why it's your favorite, these 'HackTheBox like' challenges with multiple steps are always so satisfying to solve.
    A perfect challenge to develop an efficient post-exploitation workflow while sharpenning your observation skills!

  • @Helloworldred
    @Helloworldred Рік тому

    you should stop the lizard overlords
    help the resistance

  • @leonardok1761
    @leonardok1761 Рік тому

    Hello, I think that Flask debug mode is not known for being secured, is this exploit working on a production env? Do you have recommandations to prevent those backdoors or Flask is simply dangerous? Thanks for this great video.

    • @sorenkirksdjfk7310
      @sorenkirksdjfk7310 Рік тому +6

      flask is fine, he created a scenario that left out a vulnerability, it wasnt flask's fault.

    • @saarza9991
      @saarza9991 Рік тому

      ​@@sorenkirksdjfk7310
      flask: 😢

  • @CaptTerrific
    @CaptTerrific Рік тому

    3:57 IANAH... is this going to be as simple as piping in another command? :D

  • @Lampe2020
    @Lampe2020 Рік тому +2

    12:12 Instead of the list of tuples, why don't you use a dict?

  • @BryceDixonDev
    @BryceDixonDev Рік тому +1

    "werkzeug" is pronounced "verk-zoig" by the way

  • @epic_labs
    @epic_labs Рік тому

    TIL debug mode is dangerous :o

  • @possessedllama
    @possessedllama 11 місяців тому

    If you had access to sudo, why couldn't you just do sudo cat /root/flag.txt? Or am I misunderstanding something about the challenge?

    • @antiandrogen
      @antiandrogen 11 місяців тому

      Sudoers allows you to control both which commands a user/group can run and with what level of authentication. In this case the app's user had access to run dosbox as root without a password, and no sort of access to any other command

  • @user-bg1xh3yl5o
    @user-bg1xh3yl5o Рік тому

    what is he using for the terminal autocomplete or predictive text or whatever it is?

  • @seanbrisson7928
    @seanbrisson7928 Рік тому

    1:58 yea welll u know 'Encoding' 👀 I mean we had the same job until it was illegal 😎

  • @Angelinajolieshorts
    @Angelinajolieshorts Рік тому +6

    A great explainer . ❤❤❤

  • @MarcusAndersonsBlog
    @MarcusAndersonsBlog Рік тому +1

    Tac? Tach? Tak? What ? Are you serious? You cant even use the right word for a "-".

  • @moomoomamoo
    @moomoomamoo 10 місяців тому

    paused at 8ish minutes. As a frontend dev who didn't do much python stuff, I did not see anything wrong

  • @lpls
    @lpls 11 місяців тому

    I'd never implement it this way.

  • @a2sbestos768
    @a2sbestos768 11 місяців тому

    you need `global` modifier to overwrite variable, not to access it

  • @Pohakoo
    @Pohakoo 11 місяців тому

    Could you add chapters to this video

  • @MortvmMM
    @MortvmMM Рік тому

    Stop hacking kids high school projects! I'm serious, those were 'made to be hacked'...

  • @Classfied3D
    @Classfied3D 11 місяців тому

    2:30 in... I know where this is going...
    Edit: And it also looks like there's an XSS vulnerability ;-;

  •  Рік тому

    Damn I just got unskipable ads😭

  • @kgopikkk
    @kgopikkk Рік тому

    really awsm... love the way you explained

  • @l15t3nr
    @l15t3nr Рік тому +1

    Great video! My question is, why doesn’t the server need to be restarted after the bad app code is injected?

  • @zloy_base64
    @zloy_base64 Рік тому +1

    hello bro, Can you make a channel with Russian voiceover? For example, a neural network

  • @TimelessCode
    @TimelessCode Рік тому

    oh shit i thought it was gonna be put a cmd inside of the filename but this is genius this way u can grab the ssh key

    • @aidenberzins
      @aidenberzins 11 місяців тому

      and leave yourself a backdoor for later too

  • @vk8a8
    @vk8a8 11 місяців тому

    He thrungs it ☹️

  • @SchoobyDrew
    @SchoobyDrew Рік тому +1

    oh... another ctf video, thanks for the misleading title

  • @random6033
    @random6033 11 місяців тому

    Why the hell are people using Kali Linux

  • @logiciananimal
    @logiciananimal Рік тому

    Using dosbox to privesc is new to me ...

  • @trustedsecurity6039
    @trustedsecurity6039 Рік тому

    What advantage do people find in this challenge to use python? I use it when i need to manipulate the response and do something with it like some decoding, reencoding and send it again but here i dont see any advantage at all.

    • @aidenberzins
      @aidenberzins 11 місяців тому

      He just happens to know Python its a fairly easy language to pick up especially for red team.

  • @sdafasfF
    @sdafasfF Рік тому

    yup command injection

  • @OGPargon
    @OGPargon Рік тому

    No wonder anonfiles gone you probably took down

  • @yajusgakhar6969
    @yajusgakhar6969 Рік тому

    Love his channel

  • @AHN1444
    @AHN1444 10 місяців тому

    filename

  • @WarrenGarabrandt
    @WarrenGarabrandt Рік тому +1

    Hackers respect him.
    Webmasters fear him.

  • @ImNotSion
    @ImNotSion Рік тому

    Beautiful 💓

  • @halopronesishere4019
    @halopronesishere4019 Рік тому

    oh yeah. Finally again some seth rogen hacking vid :)

  • @matejkuka797
    @matejkuka797 Рік тому

    nice t-shirt :)

  • @Jupek5936
    @Jupek5936 Рік тому

    nwm kurwa o czym to jest a jestem na 22:34

  • @InfernalOd1n
    @InfernalOd1n Рік тому

    very enjoyable.

  • @petsoukos
    @petsoukos Рік тому

    crazy...

  • @fresa6354
    @fresa6354 Рік тому

    Que malas vibras me da el chaval. 🤓☝🏻

  • @Pentester2Pentester
    @Pentester2Pentester Рік тому

    nice gpt flask app 😂

  • @u28OO
    @u28OO Рік тому

    desu desu desu

  • @MatinDevs
    @MatinDevs 11 місяців тому

    wow

  • @Iongjump
    @Iongjump 11 місяців тому

    that's awesome

  • @alessandrovalenza779
    @alessandrovalenza779 10 місяців тому

    Non ho capito un cazzo

  • @PinguNoot11201
    @PinguNoot11201 Рік тому

    11th comment

  • @gege42o83
    @gege42o83 Рік тому

    first

  • @magnus4121
    @magnus4121 Рік тому

    Cool!

  • @MartinBarker
    @MartinBarker Рік тому

    You got something wrong, "you typically see on Linux or Mac based operating systems", the default for these is that is not the case, Mac uses or '
    ' Linux uses or '
    ', windows uses '
    '. so please don't lie to people to seem like windows is the one in the wrong they are all different.

    • @jell0goeswiggle
      @jell0goeswiggle Рік тому +3

      Mac Classic used
      , but it's been over 20 years since OSX released, and that uses the POSIX line ending. So he's only incorrect if you're looking at extremely old files.
      Windows more accurately represents a typewriter (and possibly some old terminals), but I don't believe he called it incorrect, just different. Although in the case of a typewriter, the order of carriage return and line feed doesn't really matter.

  • @Mezzosd
    @Mezzosd Рік тому

    Nice

  • @NoName-rz4or
    @NoName-rz4or Рік тому

    Is it your real voice or you are using some sort of converter to make it deep? Its not good at all..

  • @johnburrows7938
    @johnburrows7938 11 місяців тому

    Why are you shouting?

  • @すぺの腹
    @すぺの腹 Рік тому

    nice

  • @cyber_space09
    @cyber_space09 Рік тому

    😂❤❤❤❤🎉💀💤 Cool ⚡🧃

  • @darimuhittin
    @darimuhittin Рік тому

    Shit on other people's hard work. Congratulations what a good thing to do. You are now a FBI agent.

    • @scorix_
      @scorix_ Рік тому +6

      I don't think you get the point of penetration testing. Pentesters like John are employed by companies to test their systems against common bugs and exploits such as these here. After that, they report a full description how they achieved access and the company can fix their loopholes. It is necessary for big companies to have people constantly testing against their systems so hackers cannot compromise them. This video shows you a potential way of exploiting dos_to_unix and how wrong it can go, so pentesters can look for these kind of things when testing.
      It is never a good way to just "not test your system and close source everything", because hackers will try to get in, no matter what. Better be prepared and have obvious loopholes closed by pentesters. Big companies such as google even give out prices for bugs others find, and they can go into the 100k reaches depending on how bad the compromise gets.

    • @nomad_swe
      @nomad_swe Рік тому +8

      It's not someone elses work? He literally mentioned that this is a challenge he himself created for a CTF event. It's literally code that is meant to be hackable if you know what you're doing, that's part of the challenge...

    • @sophiophile
      @sophiophile Рік тому +2

      What are you talking about. He created the website for part of a fun hacking challenge. You are literally the one shitting on other people's hard work, ironically.

  • @txfalkon2882
    @txfalkon2882 Рік тому +2

    thanks for the efforts you put in to deliver awesome knowledge and we hit 1M subs. 2M next --------->>---->>

  • @muthuijr
    @muthuijr Рік тому +2

    Thank You @ JohnHammond

  • @WoWUndad
    @WoWUndad Рік тому

    Hi man thank u for directions i was able to hack facebook and read my gfs messages

  • @HarvestHaven09
    @HarvestHaven09 Рік тому

    Ultimate 🥏