for test in tests: print(f"\n=== {test['name']} ===") try: r = requests.get(hidden_url, headers=test['headers'], verify=False, timeout=5) if"flag"in r.text.lower() or"ctf"in r.text.lower(): print(">>> 🚩 Possible flag here!") print(r.text) # 检查响应头 for h, v in r.headers.items(): if'flag'in h.lower() or'ctf'in h.lower(): print(f">>> 🚩 Header {h}: {v}") except Exception as e: print("Error:", e)
# 测试 HEAD 方法 print("\n=== 7. HEAD + Robot ===") try: r = requests.head(hidden_url, headers={"User-Agent": "Robot"}, verify=False, timeout=5) print("HEAD response headers:") for h, v in r.headers.items(): print(f"{h}: {v}") if'flag'in h.lower() or'ctf'in h.lower(): print(f">>> 🚩 Header {h}: {v}") except Exception as e: print("Error:", e)
key=1 G = PSL(2, 11) key*=G.order() G = CyclicPermutationGroup(11) key*=G.order() G = AlternatingGroup(114) key*=G.order() G = PSL(4, 7) key*=G.order() G = PSU(3, 4) key*=G.order() G = MathieuGroup(12) key*=G.order()
假设后台的登录验证 SQL 语句类似 SELECT * FROM users WHERE username = '$username' AND password = '$password',当我们在用户名或密码输入框中输入包含 SQL 注入的内容时,就可能改变这个查询的逻辑。
比如,在用户名输入框输入 admin' OR '1'='1,密码输入框随意输入(或者也构造类似的注入语句),这样拼接后的 SQL 语句可能变成 SELECT * FROM users WHERE username = 'admin' OR '1'='1' AND password = '$password'。由于 '1'='1' 恒成立,可能就会绕过密码验证,以 admin(管理员)身份登录,从而查看特殊内容。
核心思路:利用 SQL 逻辑漏洞绕过登录验证
假设登录表单的后端 SQL 查询逻辑大致为:
sql
1
SELECT*FROM users WHERE username ='[输入的用户名]'AND password ='[输入的密码]'
当查询结果不为空时,登录成功。我们需要构造特殊输入,让这个查询恒为真,从而绕过验证。
具体注入方法(分场景尝试)
1. 最简单的万能密码(针对用户名 / 密码任意一方)
用户名输入:admin' OR 1=1#密码任意输入(如 123)拼接后 SQL 变为:sql
1
SELECT*FROM users WHERE username ='admin'OR1=1#' AND password = '123'
from Crypto.Util.number import * import hashlib import itertools
KEY = b'5ae9b7f211e23aac3df5f2b8f3b8eada' P = 8950704257708450266553505566662195919814660677796969745141332884563215887576312397012443714881729945084204600427983533462340628158820681332200645787691506 n = 44446616188218819786207128669544260200786245231084315865332960254466674511396013452706960167237712984131574242297631824608996400521594802041774252109118569706894250996931000927100268277762882754652796291883967540656284636140320080424646971672065901724016868601110447608443973020392152580956168514740954659431174557221037876268055284535861917524270777789465109449562493757855709667594266126482042307573551713967456278514060120085808631486752297737122542989222157016105822237703651230721732928806660755347805734140734412060262304703945060273095463889784812104712104670060859740991896998661852639384506489736605859678660859641869193937584995837021541846286340552602342167842171089327681673432201518271389316638905030292484631032669474635442148203414558029464840768382970333 c = 42481263623445394280231262620086584153533063717448365833463226221868120488285951050193025217363839722803025158955005926008972866584222969940058732766011030882489151801438753030989861560817833544742490630377584951708209970467576914455924941590147893518967800282895563353672016111485919944929116082425633214088603366618022110688943219824625736102047862782981661923567377952054731667935736545461204871636455479900964960932386422126739648242748169170002728992333044486415920542098358305720024908051943748019208098026882781236570466259348897847759538822450491169806820787193008018522291685488876743242619977085369161240842263956004215038707275256809199564441801377497312252051117441861760886176100719291068180295195677144938101948329274751595514805340601788344134469750781845 e = 65537
# 爆破所有6字节key for key_bytes in itertools.product(range(256), repeat=6): key = bytes(key_bytes) if hashlib.md5(key).hexdigest().encode() == KEY: print("Found key:", key) key_int = bytes_to_long(key) p = P ^ key_int # 普通 XOR
# 检查 p 是否整除 n if n % (p**3) == 0: q2 = n // (p**3) q = isqrt(q2) if q * q == q2: print("p =", p) print("q =", q)
a = 295789025762601408173828135835543120874436321839537374211067344874253837225114998888279895650663245853 p = 516429062949786265253932153679325182722096129240841519231893318711291039781759818315309383807387756431 hint = [184903644789477348923205958932800932778350668414212847594553173870661019334816268921010695722276438808, 289189387531555679675902459817169546843094450548753333994152067745494929208355954578346190342131249104, 511308006207171169525638257022520734897714346965062712839542056097960669854911764257355038593653419751, 166071289874864336172698289575695453201748407996626084705840173384834203981438122602851131719180238215, 147110858646297801442262599376129381380715215676113653296571296956264538908861108990498641428275853815, 414834276462759739846090124494902935141631458647045274550722758670850152829207904420646985446140292244]
# 验证 a 是否正确(题目给了 a,但我们可以验证) diff1 = (hint[1] - hint[0]) % p diff2 = (hint[2] - hint[1]) % p a_calc = (diff2 * pow(diff1, -1, p)) % p print("验证 a:", a == a_calc) # 应该为 True
# 计算 m m = (hint[1] - a * hint[0]) % p
# 转为字节 flag_bytes = long_to_bytes(m) flag = flag_bytes.decode()
banner = """ Welcome to Cathylin's cryptography learning platform, where we learn an algorithm through an interesting problem. There is a frog on the grid point (a, b). When a > b, it will jump to (a-b, b); when a < b, it will jump to (a, b-a); and when a = b, it will stay where it is. Next, I will provide five sets of (a, b), and please submit the final position (x, y) of the frog in sequence If you succeed, I will give you a mysterious flag. """ print(banner)
import re import random from secret import flag
cnt = 0 while cnt < 5: a = random.randint(1, 10**(cnt+1)) b = random.randint(1, 10**(cnt+1)) print( str(cnt+1) + ".(a,b) is: (" + str(a) + "," + str(b) + ")") user_input = input("Please input the final position of the frog (x,y) :") pattern = r'[()]?(\d+)[,\s]+(\d+)[)]?' match = re.match(pattern, user_input.strip()) ifmatch: x, y = map(int, match.groups()) else: print("Unable to parse the input. Please check the format and re-enter") continue
original_a, original_b = a, b while a != b: if a > b: a = a - b else: b = b - a
if x == a and y == b: print("Congratulations, you answered correctly! Keep going for " + str(4-cnt) + " more times and you will get the mysterious flag!") cnt += 1 else: print("Unfortunately, you answered incorrectly. The correct answer is({}, {}). Please start learning again".format(a, b)) break
if cnt == 5: print("Congratulations, you answered all the questions correctly!") print("Mysterious Flag:" + flag)
Welcome to Cathylin’s cryptography learning platform, where we learn an algorithm through an interesting problem.
There is a frog on the grid point (a, b). When a > b, it will jump to (a-b, b); when a < b, it will jump to (a, b-a); and when a = b, it will stay where it is.
Next, I will provide five sets of (a, b), and please submit the final position (x, y) of the frog in sequence
If you succeed, I will give you a mysterious flag.
解答:
题目 jump_frog.py 是一个交互程序,它模拟一只青蛙在坐标 (a, b) 上,按照规则跳跃:
如果 a > b,则跳到 (a-b, b)
如果 a < b,则跳到 (a, b-a)
如果 a == b,则停止
这其实就是 辗转相减法(Euclidean algorithm 的减法版本),最终青蛙会停在 (g, g),其中 g = gcd(a, b)。