defencrypt(m, c, a, b): for i inrange(len(m)): ch=m[i] t=(letter.index(ch) * a + b) % 62 c.append(letter[t]) d = ''.join(c) print(d)
m = c = [] a = b =
assert ("flag"in m)
print("加密后的密文为:") Cipher = encrypt(m, c, a, b) flag = hashlib.md5("".join(str(m)).encode("utf8")).hexdigest() #print(flag) """ 加密后的密文为: xGJ13kkRK9QDfORQomFOf9NZs9LKVZvGqVIsVO9NOkorv """
仿射密码加密,先根据密文和明文,爆破各位置存在 flag 字符串情况下对应的 a,b 值,再解密整串密文。
defencrypt(m, a, b): c = [] for i inrange(len(m)): ch=m[i] t=(letter.index(ch) * a + b) % 62 c.append(letter[t]) d = ''.join(c) return d
s='xGJ13kkRK9QDfORQomFOf9NZs9LKVZvGqVIsVO9NOkorv' for a inrange(50): for b inrange(50): Cipher = encrypt('flag', a, b) for k inrange(len(s)-3): if Cipher==s[k:k+4]: print(Cipher,a,b) # korv 11 17
解密:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
a=11 b=17
defdecrypt(m, a, b): import gmpy2 c = [] for i inrange(len(m)): ch=m[i] t=((letter.index(ch) - b) * gmpy2.invert(a,62)) % 62 c.append(letter[t]) d = ''.join(c) return d
m=decrypt(s, a, b) print(m) flag = hashlib.md5("".join(str(m)).encode("utf8")).hexdigest() print(flag) # Oh62Affine1sSti1lN0tSecureEnoughToProtectflag # 2b9b99caae1cc49e5b5aacbc8cc22350
flag:flag{2b9b99caae1cc49e5b5aacbc8cc22350}
LINE-GENERATION-TEST
“Sorry, Tazmi, I can’t hold you in my arms anymore” Who said that? flag{md5(result)}
from gmpy2 import * nl=[...] el=[...] cl=[...] ind=[] nl_s=sorted(nl) for i inrange(7): ind.append(nl.index(nl_s[i])) print(ind) e=[] n=[] c=[] for i inrange(7): e.append(el[ind[i]]) n.append(nl[ind[i]]) c.append(cl[ind[i]])
n = c = e = 0xe18e import gmpy2 p = gmpy2.iroot(n//10,2)[0] while1: p = gmpy2.next_prime(p) if n%p==0: break q = n//p f = (p-1)*(q-1) d = gmpy2.invert(e//2,f) mm = pow(c,d,n) print(mm)
defrabin_decrypt(c, p, q, e=2): n = p * q mp = pow(c, (p + 1) // 4, p) mq = pow(c, (q + 1) // 4, q) yp = gmpy2.invert(p, q) yq = gmpy2.invert(q, p) r = (yp * p * mq + yq * q * mp) % n rr = n - r s = (yp * p * mq - yq * q * mp) % n ss = n - s return (r, rr, s, ss) m = rabin_decrypt(mm,p,q) for i inrange(4): try: print(bytes.fromhex(hex(m[i])[2:])) except: pass # b'flag{6d22773623d3d5c871692e9985de5f16}'
c = list('0101110100100111011011011000111010000111101000101010100100100011010111011000010010100101110110011101110110010100010111001110010011101010111011001100011011010110001010011111111110100110101010101110100110011010110101110110000110010101010000010110100110110110001110101011000011110100011011100101101101001000110010100111000111001111010101011011111110010111100101111001010000100010100001000111010011011111010011101100011101011010011010110001101110110110000110010011001101100000110000110100101010010010110101100101111101110000010011101110010101110100011101100110111111001010') c=[int(k) for k in c]
hp = '' for i inrange(568): (status,out) = lfsr(status,mask) hp += str(c[i]^out)
hp = int(hp, 2) print(hp) # 484896331241166236766986322307256381427323829969266475890843705533431739217993785274442520213477613786483789873490025705365184544110819157393140954140256890174240795425112
# Sage n = 9363543374665338283861145656340115756598328744870620756798779080826725774691364161648335378062705433999048117564356637094421930886166369832353405527855104576202658647651524758179962855692461154859961903531990172279764099199157181167775307950690492969859829926808950964120678082460448847927074487568619536568740301649988555476490206693181162301088156855926656544441682939839165455244630182978802660669255401576213941067679888164237586879364615664942234247896214195262510935345922512831632385741735810122730130366521612834556565838623708828780093323310348242654778247293430853566054703991781432542625271396246500576703 hp = 484896331241166236766986322307256381427323829969266475890843705533431739217993785274442520213477613786483789873490025705365184544110819157393140954140256890174240795425112
import string dic = string.digits + "abcdef"
for a in dic: for b in dic: pp = hex(hp) + a + b #p需要用0补全到1024位 pp += '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' #要加的数字与补全p时0的个数有关 pp = int(pp, 16) p_fake = pp+0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 pbits = 1024 kbits = pbits-576 pbar = p_fake & (2^pbits-2^kbits) #print("upper %d bits (of %d bits) is given" % (pbits-kbits, pbits)) PR.<x> = PolynomialRing(Zmod(n)) f = x + pbar try: x0 = f.small_roots(X=2^kbits, beta=0.4)[0] # find root < 2^kbits with factor >= n^0.4 print(x0 + pbar) except: pass # 90225006288627020933267024425797647042965554486273674145474629022335483579168020321334177600624475358419458781387021577078957978886555066264514364951229871833611713144617155837023313756741716041993159155093522769416742461683810041045361926334946115547487234272520914249496954864904467634471167509689549908477
最后常规RSA:
1 2 3 4 5 6 7 8 9 10 11
p = 90225006288627020933267024425797647042965554486273674145474629022335483579168020321334177600624475358419458781387021577078957978886555066264514364951229871833611713144617155837023313756741716041993159155093522769416742461683810041045361926334946115547487234272520914249496954864904467634471167509689549908477 n = 9363543374665338283861145656340115756598328744870620756798779080826725774691364161648335378062705433999048117564356637094421930886166369832353405527855104576202658647651524758179962855692461154859961903531990172279764099199157181167775307950690492969859829926808950964120678082460448847927074487568619536568740301649988555476490206693181162301088156855926656544441682939839165455244630182978802660669255401576213941067679888164237586879364615664942234247896214195262510935345922512831632385741735810122730130366521612834556565838623708828780093323310348242654778247293430853566054703991781432542625271396246500576703 c = 3641304537029815746727163894554557322382012539953948183406308231174259571263608621970973671202001456955622458371303424750815017578104069924877881162707673935496925529412748663209884628320657034190702348924814794263041483260377960569530869386619921425415323912964305979776909598200202236912823968867485696101691879580799000240715778010424877093758489309380968229017074542588151574195295436881889313935734282141447498134543053106463951864974512375314091440713165047188590693431938599822340588934591712592995622334522799914563528630705687647950894928965913199772209825508001274120556508220248069647851360567609656517789 q = n//p e = 0x10001 import gmpy2 f = (p-1)*(q-1) d = gmpy2.invert(e,f) m = pow(c,d,n) print(bytes.fromhex(hex(m)[2:])) # b'flag{fbbce1e3aa690ebb49039241f940ed26}'
rows, err := db.Sqlite.Query("SELECT * FROM languages;") if err != nil { fail(w, "Something wrong") fmt.Println(err.Error()) return } defer rows.Close()
res := make([]Language, 0) for rows.Next() { var pl Language _ = rows.Scan(&pl.Id, &pl.Name, &pl.Votes) res = append(res, pl) } err = json.NewEncoder(w).Encode(res) }
funcSearch(w http.ResponseWriter, r *http.Request) { reqBody, _ := ioutil.ReadAll(r.Body)
query := fmt.Sprintf("SELECT * FROM languages WHERE votes >= %d OR name LIKE '%s';", votes, name) rows, err := db.Sqlite.Query(query) if err != nil { fail(w, "Something wrong") fmt.Println(err.Error()) return } res := make([]Language, 0) for rows.Next() { var pl Language _ = rows.Scan(&pl.Id, &pl.Name, &pl.Votes) res = append(res, pl) } err = json.NewEncoder(w).Encode(res) }
funcFlag(w http.ResponseWriter, r *http.Request ) { action:= r.URL.Query().Get("action") if action == "" { fail(w, "Error getting action") return }
对于第1点,尝试构造含两个 name 参数的JSON,在python中认JSON中第二个 name,而go中认JSON中第一个 name,利用这种差异构造:{"votes":1,"name":"-1' union select 1,secret,3 from token --+","name":[]},绕过得到token值,得到 re@l1y_4th_T0k3n。