writeup 攻防世界 Decrypt-the-Message

本文介绍了PoemCode加密解密方法,通过分析一首诗和密文,找出关键词组合进行解密。经过筛选,得出可能的关键词组合,并使用Python脚本进行解密,最终成功破解密文,展示了解密过程的关键步骤和技术要点。
摘要由CSDN通过智能技术生成

在阅读之前,请确认是否处于这个地址,这是对本菜鸟辛勤码字最大的鼓励啦,感激不尽~


拿到题目,记事本打开,发现是一首诗后面跟着密文,所以想到是PoemCode。关于PoemCode更详细的加解密原理介绍可以参阅我的这篇博客,本文只粗略讲步骤。

The life that I have
Is all that I have
And the life that I have
Is yours.

The love that I have
Of the life that I have
Is yours and yours and yours.

A sleep I shall have
A rest I shall have
Yet death will be but a pause.

For the peace of my years
In the long green grass
Will be yours and yours and yours.

decrypted message: emzcf sebt yuwi ytrr ortl rbon aluo konf ihye cyog rowh prhj feom ihos perp twnb tpak heoc yaui usoa irtd tnlu ntke onds goym hmpq

简要分析:

  1. 找关键词
    密文第一块是“emzcf”,意味着:
    e:第一个关键词是诗歌的第(26k+5)个词,可能是[‘have’, ‘yours’, ‘my’],
    m:第二个关键词是诗歌的第(26k+13)个词,可能是 [‘life’, ‘shall’, ‘be’],
    z:第三个关键词是诗歌的第(26k+26)个词,可能是[‘life’, ‘pause’],
    c:第四个关键词是诗歌的第(26k+3)个词,可能是[‘that’, ‘have’, ‘peace’],
    f:第五个关键词是诗歌的第(26k+6)个词,可能是[‘is’, ‘and’, ‘years’]
    这意味着,可能的关键词组合有3*3*2*3*3=162种,每种关键词对应一个解密结果。

  2. 筛掉不可能的关键词组合
    密文sebt yuwi ytrr ortl rbon aluo konf ihye cyog rowh prhj feom ihos perp twnb tpak heoc yaui usoa irtd tnlu ntke onds goym hmpq有100个字母,关键词的字母个数应该可以被100整除。
    所以像my be life that is这个组合,有14个字母,不能被100整除,就可以直接不用试了,不可能是正确组合。
    其它组合以此类推。

  3. 手动解法的话,接下来就是关键词字母标号,密文依次填进去,重新排列,获取明文内容。具体操作还是参考文章开头给的博文。

  4. 直接脚本解密,看下面的步骤。

1.把诗歌和密文分成两个文本,诗歌去掉特殊字符,记得要保留单词间的空格,否则解密会出错。

poem.txt

The life that I have
Is all that I have
And the life that I have
Is yours

The love that I have
Of the life that I have
Is yours and yours and yours

A sleep I shall have
A rest I shall have
Yet death will be but a pause

For the peace of my years
In the long green grass
Will be yours and yours and yours

cip.txt

emzcf sebt yuwi ytrr ortl rbon aluo konf ihye cyog rowh prhj feom ihos perp twnb tpak heoc yaui usoa irtd tnlu ntke onds goym hmpq

2.解密脚本PoemCode.py

# modified by Clover on 2022.05.13
import sys
import itertools
import re
from os import listdir
from os.path import isfile, join

abc='abcdefghijklmnopqrstuvwxyz'

def loadlist(infile):
	tlist = []
	for line in open(infile,'r'):
		for w in line.split(): tlist.append(w.lower())
	return tlist


def decrypt(poem, cip):
	# Load all words of the poem into a temporary list
	twords = loadlist(poem)

	# Load all cipher chunks of the ciphertext into a list
	cwords = loadlist(cip)

	# Get the code rom the first chunk and remove it from the ciphertext list
	code = []
	for i in cwords.pop(0): #get keywords tips
		code.append(abc.index(i))
	# Select only those words specified in the code in a new multi-arrayed list
	xwords = [[] for x in range(len(code))]
	for xcount, c in enumerate(code):
		tlen = c
		while(c<len(twords)):
			xwords[xcount].append(twords[c].lower())
			c+=26

	# Get all possible combinations
	CN=len(cwords)*len(cwords[0])
	for comb in itertools.product(*xwords):
		pwords = ''
		for c in comb: pwords+=c
		KN = len(pwords)
		if CN%KN!=0 : continue
		
		#re-devide the cyber text by CN/KN
		c_text=''
		for i in range(0,len(cwords)):
			c_text+=cwords[i]

		c_text_list = re.findall(r'\w{'+str(CN/KN)+'}', c_text)

		# Rearrange the chunks according to the key
		pcode = [None] * KN#len of pcode is equal to the numbers in keywords group
		count = 0
		while(count<KN):
			for al in abc:
				for pc, pl in enumerate(pwords):
					
					if al!=pl: continue
					pcode[count]=c_text_list[pc]#put cyber-text blocks in the right position
					count+=1

		# Decrypt the ciphertext
		msg = ''
		for c in range(0, CN/KN):
			for word in pcode:
				msg+=word[c]
		print msg

# first argument = poem
# second argument = ciphertxt or msg
if len(sys.argv) != 3: sys.exit(2)

decrypt(sys.argv[1], sys.argv[2])

3.运行python2 PoemCode.py poem.txt cip.txt。运行结果如下,可以看到,虽然经过了关键词组合的筛选,还是有29种可能的关键词组合,需要挑一个长得像答案的。但是如果不筛选的话,就要从162个答案里面挑,工作量更大。
认真看一下,倒数第十行是很有可能的,所以尝试提交一下这一行的数据,耶~ 破解啦~

┌──(kali㉿kali)-[~/AttackAndDefence/CRYPTO进阶/11 PoemCOde]
└─$ python2 PoemCode.py poem.txt cip.txt
uutamlgpetyosoeapdtrwikihrrtonesenolrspriuermbowclcpbfmuhgaoysotpownyuyetiiojokrtondqnhbanoryhhkfyht
ueatmlgtysuoadppetorwoikhrrpeeinlsrtonsrimremboacbufughwclpoyitopowkytsioojnyuerthdnqnhhoyohkyfbanrt
ueutmlgttyseoadpporawoikhrrpneeonlsrtsriimuemboalcbcfughwporyisopowkuytyioojnertthonqnhhnoyahkyfbrtd
ueatlgtutysodapepmorwoinrrpikeenslrothsrimrlboauecbfguhcwmpoyituowksoytioojynperthdnnhhonoyhykfabqrt
uyatmltpsouogpedaetrweikhrptenisrroslonricrembawbfupohmgucloyytopokntisewjiooyurtodnqnhbyhorhfhykant
uyutmlttpsoeogpedaraweikhrpntenosrroslriicuembalwbfcpohmguoryysopokuntiyewjioorttoonqnhnbyharhfhyktd
uyatltutpsoodgpeeamrweinrpiktenssrroolhricrlbauewbfpgohmcumoyytuoksontieowjiyoprtodnnhonbyhryhfhakqt
uyotlesoadgpeatmutprwesnroenisrrolphiktricplbcbfrgohmuamuewoyyeuoytitowjiokpsonrtornnayhdyhfhkhqonbt
uyoaletsoudgpeatmprtwesirokenisrrolphtrnicprbcebfugohmuamwolyyetoyotisowjiokpnrutordnanyhoyhfhkhqbtn
uttaeloeputpsgyodmrawpklornotinreresshriiaeucbfmwulhbocpgmorykooyoiinsujtwyeoprtthnkanhhbonfyhoryqtd
ugetalootstydempuprawroklrnsnepesohtirriioceubfplbacgmmwuhorywyoooieutkyoipnsjrtthanknhrnyhoyhqboftd
ugttalooutspydempreawrpklrnsinetesohrroiioaeubfpulbwcgmmhocrywkoooiesutnyoipjrytthhnknhronyboyhqftad
atmptgpuyooedulaetrsikhrprtiesnoswrlonreremhaowucpfmgibuclobtopjkwnsyeiioyooyurtdnqfhhboorhhytnkanty
utmpttgpeyooedularasikhrpnrtoesnoswrlrieuemhalowccpfmgibuorbsopjkuwnyyeiioyoorttonqfhnhbaorhhytnktdy
atptutgpyodoeuelamrsinrpikrtessnoworlhrerlhaueowcpgfmicbumobtujksownyeoiiyyooprtdnfhonhboryhhtankqty
otpegaydouelatmutrpssnroriesnworlphikrteplhcorcgfimbuamueowbeujywtyoiyiookpsorntrnfahdoyhthnkhqontby
oapetguydouelatmrptssirokriesnworlphrtneprhceoucgfimbuamowlbetjyowsyoiyiookprnutrdfanhooyhthnkhqtbny
gtetyapdpeoulaomutrsrnopeitsroswrlnhikreolcacrwghmpibufmueobwuykytnojieyooipsorthnahodbyfhrtnkhqonty
gaettyupdpeoulaomrtsriokpeitsroswrlnhrneorceacuwghmpibufmolbwtyokysnojieyooipruthdanhoobyfhrtnkhqtny
ifyouthinkcryptographyistheanswertoyourproblemthenyoudonotknowwhatyourproblemisabcdefghijklmnopqrstu
etoyotetpguldampursaoknesnoprrwrslhtireicefcplmahoibgumwuobryoiyeuikjwyooopnsrttanhornhhfhtnykqbotyd
ttoyouteppguldamresapknesinotrrwrslhroeiaefcpulmwhoibgumocbrkoiyesuinjwyoooprytthnhoronhbfhtnykqtayd
putoamypetdugtlaoresriknihetonswrprlsroehuefrmcwclgioabupombjsoitpynyuoywkooeritfonhdqobanythhnkrthy
tteoeputaplgrysodmuapkonotinlrrrreesshwiaecfmwuluhboocbpgmirkoyiinsuojowryteopythnahhbonkfnhtoyryqtd
getootatlrsydempupuaroknsnlprreesohtirwiocefpluabobcgmmwuhirwyoieuokortyoipnsjythanhrnkhntyoyhqboftd
gttooutaplrsydempeuarpknsinltrreesohrowioaefpuluwbobcgmmhcirwkoiesuonortyoipjyythhnhronkbntyoyhqfatd
aetoteltpoygsdrmpuualoksnorprneresrhtiwiuceplmbahfcobgomwuiroyoeuiokjiywtorpnsytkanrnhnhfhohyytqbotd
attoutelppoygsdrmeualpksinortrneresrhowiuaepulmbwhfcobgomcirokoesuionjiywtorpyytkhnronhnbfhohyytqatd
aputampetloysdgtroeulrikihtonrneesrprsowuhuermwclbfcbgoaopmiojsotpnyuoiytowkreiykfondqbannhoyyhhtrht

OSCP 2023 Challenge Writeup-MedTech-CSDN博客是一个关于OSCP挑战赛的技术解析博客。在这篇博客中,作者详细讲解了一个名为MedTech的挑战项目,并提供了解决该挑战所需的步骤和工具。 这篇博客的开头介绍了OSCP证书的重要性和它在信息安全领域的认可度。接着,作者向读者介绍了挑战项目MedTech的背景和目标。MedTech是一个模拟医疗技术公司的网络环境,参与者需要在该环境中寻找漏洞、获取权限,最终控制主机,获取FLAG。 在解决这个挑战的过程中,作者详细介绍了使用的工具和技术。例如,他讲解了利用漏洞扫描工具Nmap进行主机发现和服务探测的步骤,以及如何使用Metasploit框架进行漏洞利用和提权。 博客中还涵盖了其他一些有关网络渗透测试的技术,如枚举、社会工程学和Web应用程序漏洞利用。作者详细解释了每个技术的原理和实际应用。 在解决MedTech挑战的过程中,作者还分享了一些遇到的困难和技巧。他提到了一些常见的错误和陷阱,并分享了如何避免它们的经验。 最后,作者总结了整个挑战的过程,并分享了他在完成挑战时的成就感和收获。他强调了在这个过程中学到的技能和知识的重要性,并鼓励读者积极参与类似的挑战和项目。 这篇博客不仅提供了对OSCP挑战赛的深入了解,而且为读者提供了解决类似问题的思路和方法。它对于那些对信息安全和网络渗透感兴趣的读者来说是一个很有价值的参考资源。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值