Python Web Hacking: Remote Code Execution | Natas: OverTheWire (Level 10)

John Hammond · Intermediate ·🔐 Cybersecurity ·8y ago

Key Takeaways

Demonstrates a remote code execution vulnerability in a Natas challenge

Full Transcript

what's up everybody John Hammond here back at the nattis war game from over thewire uh just finished up on level 10 now uh was looks to be pretty similar to level 9 uh I went ahead and ran the script um so we can check out the URL what's in the page right here and let's actually view it it says for security reasons we now filter on certain characters uh and let's has another fine words containing a needle and a Hy stack uh same functionality we had seen in the previous level but we can take a look at the s code and see what they're doing since they say they're filtering on certain characters so let's add that to our URL just do the get request on that and as usual this is pretty gross but we can run tidy HTML on it um we can run the HTML de entiti entities and this BR or HTML Break Tag it's kind of annoying we can control h to find replace those V and let's replace them with nothing I'm going to hit control alt and enter here so they all go away cool so we've got the PHP code denoted here um and we can search for a key that's um determined whether or not um we have actually submitted a request or posted to this web page and it's testing that determining whether or not this key exists if needle if that form input was provided and if it doesn't equal an empty string if if it were actually provided from this previous conditional it'll test if prg match um looks like braces of uh Square braces containing a semicolon pipe symbol Amper sand all inside the key um so preg match is um Regular expressions and it's testing is there a match for anything in this regular expression set you can tell it's regular Expressions by the forward slash beginning and ending and in regular Expressions the square brace means anything within this character set so anything like a semicolon pipe symbol or Amper sand in this case will return a match and it's testing on the key that's provided so whatever we actually input and otherwise it will return out it'll display input contains an illegal character otherwise it'll go ahead and run the command like it had in the previous level actually run GP um we can view this in the web page if we wanted to let me fire that up here steal the URL open up Firefox and we are in nattis 10 so let me just copy and paste this password here okay great so if we had anything with a semicolon at the end it'll say oh this input contains an Legal character so we can't use those but that's okay because in the last video for natus 9 um we didn't end up using any of those characters the exploit quote un quote or the technique we ended up using was posting to this page and doing some command injection to say I want to grip for anything with the period because of regular expressions in the file uh the like nattis password file in this case we want nattis 11 now because we're on level 10 we want to advance to the next level and then we use a uh pound symbol or a hashtag to comment out the rest of the line so it didn't actually check out dictionary. text it would just only uh run grep and process through the password file for the next level so since the hashtag or that pound symbol is not in this illegal character list it's not in this regular expression Set uh we can run this exact same thing and we should still be able to you know get the next password so let's run that post command um run that function and let's see what's returned to us go ahead and print the content out I just changed URL to make sure it's actually interacting with the page keep in mind you may have to do that if you forgot to but output here is the password for the next level right that okay we're done awesome because all we did was just that little technique um grap for anything the period here um specify the file that we want ET Rus web pass notus 11 and then comment out the rest because since there wasn't any sanitization or any filtering done to really um what's being input into that GP command or into that like system call that shell command um we were able to just inject just like that same as the last level pretty easy pretty simple really just reusing that same exploit and now we're ready to move on let's go to uh natus 11 create a script for that I'm going to have to replace it because I already had some stuff that I was just experimenting with and now we can check out what this level is this is going to be a pretty big one pretty long video for uh natus 11 um so that's why I wanted to offset with a pretty short video here for natus 10 because it's really the same attack as the nus level 9 UM thanks for watching guys hope you're enjoying these I hope you're enjoying this video um if you do please like the video comment tell me what you think uh what more videos you want to see if you're willing to subscribe and thanks for watching guys hope you're enjoying these see you later

Original Description

If you would like to support me, please like, comment & subscribe, and check me out on Patreon: https://patreon.com/johnhammond010 E-mail: johnhammond010@gmail.com PayPal: http://paypal.me/johnhammond010 GitHub: https://github.com/JohnHammond Site: http://www.johnhammond.org Twitter: https://twitter.com/_johnhammond
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from John Hammond · John Hammond · 0 of 60

← Previous Next →
1 Code Commentaries? PHP to JavaScript in Bash and PHP!
Code Commentaries? PHP to JavaScript in Bash and PHP!
John Hammond
2 Tutorials? MySQL connection with PHP and Bash!
Tutorials? MySQL connection with PHP and Bash!
John Hammond
3 Variable Naming in Python! Happy Birthday, Linux! Nokia N900!
Variable Naming in Python! Happy Birthday, Linux! Nokia N900!
John Hammond
4 JavaScript Splits The URL!
JavaScript Splits The URL!
John Hammond
5 HTML Tables in Python!
HTML Tables in Python!
John Hammond
6 HTML, Net Shares, GML!
HTML, Net Shares, GML!
John Hammond
7 Python 08 Programming Style and Comments
Python 08 Programming Style and Comments
John Hammond
8 Python 26 Object Oriented Programming
Python 26 Object Oriented Programming
John Hammond
9 75 Python Tutorials, Out Now!
75 Python Tutorials, Out Now!
John Hammond
10 Batch 14 Mathematical Expressions
Batch 14 Mathematical Expressions
John Hammond
11 Batch 85 Array Append
Batch 85 Array Append
John Hammond
12 Batch 86 Array Count
Batch 86 Array Count
John Hammond
13 Batch 87 Array Index
Batch 87 Array Index
John Hammond
14 Batch 88 Array Insert
Batch 88 Array Insert
John Hammond
15 Batch 89 Array Remove
Batch 89 Array Remove
John Hammond
16 Batch 90 Array Reverse
Batch 90 Array Reverse
John Hammond
17 Python [colorama] 00 Installing on Linux
Python [colorama] 00 Installing on Linux
John Hammond
18 Python [colorama] 09 Cursor Position
Python [colorama] 09 Cursor Position
John Hammond
19 Python [hashlib] 02 Algorithms
Python [hashlib] 02 Algorithms
John Hammond
20 Python 00 Installing IDLE on Linux
Python 00 Installing IDLE on Linux
John Hammond
21 Python [pygame] 11 Rectangular Collision Detection
Python [pygame] 11 Rectangular Collision Detection
John Hammond
22 Python [pygame] 12 Platforming Rectangular Collision Resolution
Python [pygame] 12 Platforming Rectangular Collision Resolution
John Hammond
23 Python [XML-RPC] 01 Research
Python [XML-RPC] 01 Research
John Hammond
24 Python [pyenchant] 03 Personal Word Lists
Python [pyenchant] 03 Personal Word Lists
John Hammond
25 FancyURLopener Authentication and User-Agent [urllib] 03
FancyURLopener Authentication and User-Agent [urllib] 03
John Hammond
26 Python 04: PEP8 Coding
Python 04: PEP8 Coding
John Hammond
27 Python Challenge! 17 COOKIES
Python Challenge! 17 COOKIES
John Hammond
28 Google CTF 2016: Ernst Echidna
Google CTF 2016: Ernst Echidna
John Hammond
29 Google CTF 2016: Spotted Quoll
Google CTF 2016: Spotted Quoll
John Hammond
30 Google CTF 2016: Can you Repo It?
Google CTF 2016: Can you Repo It?
John Hammond
31 Google CTF 2016: No Big Deal
Google CTF 2016: No Big Deal
John Hammond
32 Google CTF 2016: In Recorded Conversation
Google CTF 2016: In Recorded Conversation
John Hammond
33 Homemade CTF Challenge: 01 "Orchestra"
Homemade CTF Challenge: 01 "Orchestra"
John Hammond
34 Homemade CTF Challenge: 02 "Bae's Base"
Homemade CTF Challenge: 02 "Bae's Base"
John Hammond
35 Homemade CTF Challenge: 03 "Web Hunt"
Homemade CTF Challenge: 03 "Web Hunt"
John Hammond
36 Homemade CTF Challenge: 04 "UPX"
Homemade CTF Challenge: 04 "UPX"
John Hammond
37 Homemade CTF Challenge: 05 "The Assumption Song"
Homemade CTF Challenge: 05 "The Assumption Song"
John Hammond
38 Homemade CTF Challenge: 06 "A Brisk Stroll"
Homemade CTF Challenge: 06 "A Brisk Stroll"
John Hammond
39 Homemade CTF Challenge: 06 "I lost my password!"
Homemade CTF Challenge: 06 "I lost my password!"
John Hammond
40 web25 :: Mr. Robot : EKOPARTY CTF 2016
web25 :: Mr. Robot : EKOPARTY CTF 2016
John Hammond
41 web50 : RFC 7230 :: EKOPARTY CTF 2016
web50 : RFC 7230 :: EKOPARTY CTF 2016
John Hammond
42 misc50 : Hidden inside EKO :: EKOPARTY CTF 2016
misc50 : Hidden inside EKO :: EKOPARTY CTF 2016
John Hammond
43 Hack The Vote 2016 CTF: Sander's Fan Club [web100]
Hack The Vote 2016 CTF: Sander's Fan Club [web100]
John Hammond
44 Hack The Vote 2016 CTF Warpspeed [forensics150]
Hack The Vote 2016 CTF Warpspeed [forensics150]
John Hammond
45 Juniors CTF 2016 :: Black Suprematic Square
Juniors CTF 2016 :: Black Suprematic Square
John Hammond
46 Juniors CTF 2016 :: Six Strange Tales
Juniors CTF 2016 :: Six Strange Tales
John Hammond
47 Juniors CTF 2016 :: Lost Code
Juniors CTF 2016 :: Lost Code
John Hammond
48 Juniors CTF 2016 :: Here Goes!
Juniors CTF 2016 :: Here Goes!
John Hammond
49 Juniors CTF 2016 :: Southern Cross
Juniors CTF 2016 :: Southern Cross
John Hammond
50 Juniors CTF 2016 :: Clone Attack
Juniors CTF 2016 :: Clone Attack
John Hammond
51 Juniors CTF 2016 :: Dirty Repo
Juniors CTF 2016 :: Dirty Repo
John Hammond
52 Juniors CTF 2016 :: Hackers Blog
Juniors CTF 2016 :: Hackers Blog
John Hammond
53 Juniors CTF 2016 :: Voting!!!
Juniors CTF 2016 :: Voting!!!
John Hammond
54 Juniors CTF 2016 :: The Good, The Bad and The Junkman
Juniors CTF 2016 :: The Good, The Bad and The Junkman
John Hammond
55 Juniors CTF 2016 :: Stop Thief!
Juniors CTF 2016 :: Stop Thief!
John Hammond
56 Juniors CTF 2016 :: ROFL
Juniors CTF 2016 :: ROFL
John Hammond
57 Juniors CTF 2016 :: Restriced Area
Juniors CTF 2016 :: Restriced Area
John Hammond
58 Juniors CTF 2016 :: Oh SSH!
Juniors CTF 2016 :: Oh SSH!
John Hammond
59 HackCon CTF 2017 TRIVIA and BONUS Challenges
HackCon CTF 2017 TRIVIA and BONUS Challenges
John Hammond
60 HackCon CTF 2017 "Bacche" Challenges
HackCon CTF 2017 "Bacche" Challenges
John Hammond

Related AI Lessons

Aflac Japan Data Breach Exposes 4.38 Million Policyholder Records
Aflac Japan's data breach exposes 4.38 million policyholder records, highlighting the importance of cybersecurity in protecting sensitive information
Dev.to · BeyondMachines
Autonomous Cyberattacks Are Coming And Our Defenses Were Built for a Different Era
Autonomous cyberattacks are emerging, requiring new defenses beyond traditional security measures
Dev.to · Arashad Dodhiya
Security Belongs on the Blueprint
Integrate security into building design to mitigate physical and cyber risks
Medium · Cybersecurity
# A 4-Line HTML File Stole the Admin’s Secret — Intigriti LeakyJar CTF Writeup
Learn how a 4-line HTML file exploited a CSRF vulnerability to steal an admin's secret in the Intigriti LeakyJar CTF challenge
Medium · Cybersecurity
Up next
You Think Your Card Declined by Mistake? It Might Be a 2026 Scam
Tolulope Michael
Watch →