UNCTF2020的奇妙经历-----Crypto&Misc部分wp
Crypto
1.easy_rsa
题目:
from Crypto.Util import number
import gmpy2
from Crypto.Util.number import bytes_to_long
p = number.getPrime(1024)
q = number.getPrime(1024)
if p > q:
a = p + q
b = p - q
print(a,b)
n = p * q
e = 65537
phi = (p-1)*(q-1)
d = gmpy2.invert(e,phi)
m = bytes_to_long(b'msg')
c = pow(m,e,n)
print(c)
#320398687477638913975700270017132483556404036982302018853617987417039612400517057680951629863477438570118640104253432645524830693378758322853028869260935243017328300431595830632269573784699659244044435107219440036761727692796855905230231825712343296737928172132556195116760954509270255049816362648350162111168
#9554090001619033187321857749048244231377711861081522054479773151962371959336936136696051589639469653074758469644089407114039221055688732553830385923962675507737607608026140516898146670548916033772462331195442816239006651495200436855982426532874304542570230333184081122225359441162386921519665128773491795370
#22886015855857570934458119207589468036427819233100165358753348672429768179802313173980683835839060302192974676103009829680448391991795003347995943925826913190907148491842575401236879172753322166199945839038316446615621136778270903537132526524507377773094660056144412196579940619996180527179824934152320202452981537526759225006396924528945160807152512753988038894126566572241510883486584129614281936540861801302684550521904620303946721322791533756703992307396221043157633995229923356308284045440648542300161500649145193884889980827640680145641832152753769606803521928095124230843021310132841509181297101645567863161780
这题目算法很简单,(a+b)/2就能得到p,一开始直接用python计算,然后报错溢出,就丢到sagemath里去了,秒出p,q
然后p,q,n,e,c就变成全部已知,那不就是有手就行了嘛(没手也行),丢脚本直接出结果
from Crypto.Util.number import long_to_bytes
from gmpy2 import *
from Crypto.Util import number
p = 164976388739628973581511063883090363893890874421691770454048880284500992179926996908823840726558454111596699286948761026319434957217223527703429627592448959262532954019810985574583860227624287638908448719207441426500367172146028171043107126122608800640249201232870138119493156975216320985668013888561826953269
q = 155422298738009940394189206134042119662513162560610248399569107132538620220590060772127789136918984458521940817304671619205395736161534795149599241668486283754795346411784845057685713557075371605135986388011998610261360520650827734187124699589734496097678970899686056997267797534053934064148348759788335157899
#q = n//p
c = 22886015855857570934458119207589468036427819233100165358753348672429768179802313173980683835839060302192974676103009829680448391991795003347995943925826913190907148491842575401236879172753322166199945839038316446615621136778270903537132526524507377773094660056144412196579940619996180527179824934152320202452981537526759225006396924528945160807152512753988038894126566572241510883486584129614281936540861801302684550521904620303946721322791533756703992307396221043157633995229923356308284045440648542300161500649145193884889980827640680145641832152753769606803521928095124230843021310132841509181297101645567863161780
#n =
e = 65537
n = p * q
phi = (p-1)*(q-1)
d = invert(e,phi)
#d =
#print(d)
m = pow(c, d, n)
#print(m)
print(long_to_bytes(m))
#flag:UNCTF{welcome_to_rsa}
2.简单的rsa
题目:
e= 18437613570247445737704630776150775735509244525633303532921813122997549954741828855898842356900537746647414676272022397989161180996467240795661928117273837666615415153571959258847829528131519423486261757569454011940318849589730152031528323576997801788206457548531802663834418381061551227544937412734776581781
n= 147282573611984580384965727976839351356009465616053475428039851794553880833177877211323318130843267847303264730088424552657129314295117614222630326581943132950689147833674506592824134135054877394753008169629583742916853056999371985307138775298080986801742942833212727949277517691311315098722536282119888605701
c= 140896698267670480175739817539898638657099087197096836734243016824204113452987617610944986742919793506024892638851339015015706164412994514598564989374037762836439262224649359411190187875207060663509777017529293145434535056275850555331099130633232844054767057175076598741233988533181035871238444008366306956934
这么大个e,直接wiener-attack,github上随便找个脚本自己改一下就行
import ContinuedFractions, Arithmetic, RSAvulnerableKeyGenerator
from Crypto.Util.number import long_to_bytes
from gmpy2 import *
from Crypto.Util import number
def hack_RSA(e,n):
'''
Finds d knowing (e,n)
applying the Wiener continued fraction attack
'''
frac = ContinuedFractions.rational_to_contfrac(e, n)
convergents = ContinuedFractions.convergents_from_contfrac(frac)
for (k,d) in convergents:
#check if d is actually the key
if k!=0 and (e*d-1)%k == 0:
phi = (e*d-1)//k
s = n - phi + 1
# check if the equation x^2 - s*x + n = 0
# has integer roots
discr = s*s - 4*n
if(discr>=0):
t = Arithmetic.is_perfect_square(discr)
if t!=-1 and (s+t)%2==0:
print("Hacked!")
return d
def hack_RSA1():
e = 18437613570247445737704630776150775735509244525633303532921813122997549954741828855898842356900537746647414676272022397989161180996467240795661928117273837666615415153571959258847829528131519423486261757569454011940318849589730152031528323576997801788206457548531802663834418381061551227544937412734776581781
n = 147282573611984580384965727976839351356009465616053475428039851794553880833177877211323318130843267847303264730088424552657129314295117614222630326581943132950689147833674506592824134135054877394753008169629583742916853056999371985307138775298080986801742942833212727949277517691311315098722536282119888605701
c = 140896698267670480175739817539898638657099087197096836734243016824204113452987617610944986742919793506024892638851339015015706164412994514598564989374037762836439262224649359411190187875207060663509777017529293145434535056275850555331099130633232844054767057175076598741233988533181035871238444008366306956934
d = hack_RSA(e, n)
m = pow(c, d, n)
print(long_to_bytes(m))
if __name__ == "__main__":
#test_is_perfect_square()
#print("-------------------------")
hack_RSA1()
#flag:unctf{wi3n3r_Att@ck}
3.鞍山带法官
题目:
这文案写的就很灵性,以致于我读完文案都不知道是什么加密,但是这密文就俩字母,盲猜一手培根加密,然后培根刚好能吃,密文刚好又是100位,5的倍数,估计八九不离十了,写个脚本把ot换ab(不想写的word有替换功能,有一说一,挺好用的)然后培根解密就完事了,大小写自己试一下就知道了
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
#Author:later_future
import string
miwen=input("请输入密文:")
count=0
msg=""
flag=""
dicts={
'aaaaa':'a','aaaab':'b','aaaba':'c','aaabb':'d','aabaa':'e',
'aabab':'f','aabba':'g','aabbb':'h','abaaa':'i','abaab':'j',
'ababa':'k','ababb':'l','abbaa':'m','abbab':'n','abbba':'o',
'abbbb':'p','baaaa':'q','baaab':'r','baaba':'s','baabb':'t',
'babaa':'u','babab':'v','babba':'w','babbb':'x','bbaaa':'y',
'bbaab':'z',}
for i in miwen:
msg+=i
count+=1
if count==5:
c=dicts[msg]
flag+=c
count=0
msg=""
continue
#小写结果
print("flag:"+flag)
#大写结果
print("flag:"+flag.upper())
#flag:unctf{PEIGENHENYOUYINGYANG}(有一说一,确实)
4.wing
题目:
提示:你过office二级了吗
这提示一看就是office里的某种字体,即使他不提示我也知道,以前有幸见过,直接对照着转换就行,哦对了字体是wingdings2,如题,最后得到flag:unctf{wingdings_is_incomprehensible}
Misc
真正的奇妙之旅从misc开始了
1.baba_is_you
题目:
记事本打开拉到最后找到一个链接
打开链接,评论区找到flag:unctf{let’s_study_pwn}
2.阴阳人编码
题目:
因为之前刚好做过类似的题,一眼看出是ook,然而通过特征符号“.?!”也可以辨别出来,于是把它变成ook应该有的样子,如图
在线网站解密得到flag:flag{9_zhe_Jiu_zhe_8_hui_8}
3.爷的历险记
题目:
打开文件发现是个rpg游戏,然后开局打不过老鼠的爷直接裂开(loser~),后来开了几个箱子升级之后爷变强了,爷拿捏了耗子,爷在一系列操作之后发现爷又打不过了,打不过就拿不到flag,然后发现有个商人,hint3卖999999,盲猜一手flag,直接上修改器,修改爷的金币,然后就买到flag了,但是爷的死宅魂燃起来了,爷决定通关,于是经过一系列神奇的操作之后爷打死了boss,又得到了一遍flag,爷觉得非常舒服
就在这时爷意识到一件事情,flag不是应该存在本地文件里的吗(wtf),爷这波又草率了,不过爷很快乐,然后这是flag:UNCTF{WelC0me_70_UNCTF2oZ0~}
4.躲猫猫
题目:
下载下来是个excel表格,但是打不开,我意识到事情没这么简单,用winhex打开看到文件头是504B,这压根不是表格,这是zip压缩文件的头,于是修改后缀为zip,果然是个压缩包,解压得到一堆文件,如图
然后查看文件名,发现一个文件叫“sharedStrings”,要素察觉,果断打开,果不其然,有一串base64,如图
解码以后得到unctf%7B7383b67de9106a6f10fdbe4e8ebc64ce%7D,然后转换一下就可以得到flag:unctf{7383b67de9106a6f10fdbe4e8ebc64ce}
5.你能破解我的密码吗
题目:
下载下来是个shadow文件,先用万能的记事本打开看了一下,是这亚子的
瞬间秒懂,直接打开虚拟机(虽然我一开始就可以直接拖虚拟机的,节目效果),拖到parrot自带的工具johnny(有gui界面的john)
然后就得到密码了
按照题目要求提交123456的md5值即可,最后拿到flag:unctf{e10adc3949ba59abbe56e057f20f883e}
6.撕坏的二维码
题目:
这题目你去了解一下二维码的原理,把原图补上一个定位角就能扫了,如图
扫码得到flag:unctf{QR@2yB0x}
7.零
题目:
提示:我瞎了看不到flag了
这玩意儿一打开,因为职业习惯,直接拉去词频分析,然后分析了个寂寞,啥也没得到,然后我注意到第一个字母“N”的列标并不是从零开始的,如图
于是我意识到事情不对劲,也不知道为什么就想到用浏览器打开了,打开以后按一手f12,就得到了这个神奇的东西,如图
不知道的东西就去百谷一下,然后得知两个名词“零宽不连字”和“零宽连字”,要素察觉“零宽”,标题又叫“零”,再看一下提示,稳了,零宽隐写(后来知道的这个名字,本来是知识盲区),找个在线网站解码就出来了,如图
得到flag:unctf{sycj24_6hvgj_8gfj}
8.YLB’s CAPTCHA
题目:
是一个输验证码的网站,输对十次就能拿到flag,但是验证码极其阴间,如图
求求你做个人,我看了个寂寞,不过我还是输对了十次拿到了flag:
UNCTF{9a1d6675-caf3-48d0-a577-8a4fe932b3e5}(动态docker,flag不是固定的)
(吐槽并不是针对的出题人,知道ylb是啥的都懂,不懂的我也不想多说,求求你做个人吧ylb,丢人)
9.mouse_click
题目:
解压附件得到一个pcapng文件,流量分析妥了,直接上wireshark,Leftover Capture Data是数据区,鼠标一般为四字节,如图
然后用tshark命令提取所有数据
tshark -r mouse_click.pcapng -T fields -e usb.capdata > data.txt
得到一个十六进制的文件,如图
然后将此文件转换为坐标文件,并用gnuplot工具还原鼠标轨迹得到下图
将图中的字翻转并大写可得到flag:unctf{U5BC@P}
10.EZ_IMAGE
题目:
附件是225张图,很明显拼图可以得到flag,通过暴力手撸当然可以得到flag,几个小时的事情,这边介绍另一种方法,主要用到了montage和gaps,如何安装自行百谷,这边就不赘述了
首先用montage将225张图片合成,*代表所有图片名称
montage *.jpg -tile 15x15 -geometry +0+0 flag.jpg
然后使用gaps拼图
gaps --image=flag.jpg --size=60 --save
得到下图
得到flag:UNCTF{EZ_MISC_AND_HACK_FUN}
11.ET-msg(未完成)
题目:
职业素养,转了各种编码之后无果,然后就没管这题了,后来放了两个提示以后又重新来做这题
提示1:阿雷:Arecibo
提示2:30 80 7
不懂不懂,百谷一下,然后奇怪的知识增加了,了解完第一个提示之后知道第二个提示是要把原文排列成30*80,变成这样
字里行间隐约可见unctf几个字母,要素察觉,然后这个看着真的难受,就写了个脚本变成了这样
然后就涉及到提示一里的阿雷西博信息了,把大括号里的东西翻译过来得到一串数字133121214201066214100215205,最高6,提示二有个7,七进制妥了,然后我就卡在这了,赛后问了其他师傅得知是要七进制转十六进制,十六进制作为hex写文件,我…裂开,出题人脑洞真大,不过论脑洞,太极八卦那题真恶心,太艹了,直接放弃治疗
赛(mang)后(mu)总(fen)结(xi)
第一次写比赛题的wp,感触颇丰,最大的感触还是自己太菜了,也没做出几道题,希望师傅们不要吐槽,另外有crypto和misc方向的师傅可以加我交流一下,头都要被锤烂了,QQ:1870843766,备注:laffey