​ 之前m1不支持x86,一直用云服务器有时候经常换,每次都需要手动搭建环境,一直想写个脚本,但有时候一直懒…终于整理出来了..

(感谢chatgpt)

​ 然后这个脚本目前还有很多小问题和可以改进的地方

要安装的内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 必要的安装
apt-get update
apt-get install python3 python3-pip python3-dev git libssl-dev libffi-dev build-essential
# 安装常用工具
sudo apt install -y git vim gdb strace ltrace socat netcat

# 安装pwntools
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pwntools

# 安装pwndbg
git clone https://github.com/pwndbg/pwndbg
cd pwndbg
sudo ./setup.sh
echo "source /ctfpwntools/pwndbg/gdbinit.py" >> ~/.gdbinit
cd ..

# 安装glibc-all-in-one
git clone https://github.com/matrix1001/glibc-all-in-one.git
cd glibc-all-in-one/
python3 update_list
cd ..

# 安装ROPgadget
pip install capstone
git clone https://github.com/JonathanSalwan/ROPgadget.git
cd ROPgadget
sudo python3 setup.py install

# one_gadget
apt -y install ruby
gem install one_gadget

# LibcSearcher
git clone https://github.com/lieanu/LibcSearcher.git
cd LibcSearcher
python3 setup.py develop
cd ..

# patchelf
apt-get install autoconf automake libtool
git clone https://github.com/NixOS/patchelf.git
cd patchelf
./bootstrap.sh
./configure
make
make check
make install
cd ..


## seccomp
# 1.添加仓库
sudo add-apt-repository ppa:brightbox/ruby-ng
sudo apt-get update
# 2.指定安装 ruby 2.6 版本
sudo apt-get install ruby2.6 ruby2.6-dev
# 3.然后安装 seccomp-tools
sudo gem install seccomp-tools

# 32位libc
dpkg --add-architecture i386
apt-get install libc6:i386
apt-get install libgtk2.0-0:i386


简单的开始

​ 简单的创建while循环,指定安装次数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /bin/bash

mkdir /ctfpwntools
cd /ctfpwntools

MAX_RETRIES=3
INSTALL_SUCCESS=false
RETRY_COUNT=0

# 更新apt源
sudo apt update
# 安装常用工具
sudo apt install -y git vim gdb strace ltrace nmap socat netcat


# 安装pwntools

while [ $RETRY_COUNT -lt $MAX_RETRIES ] && [ "$INSTALL_SUCCESS" = false ]
do
echo "Attempt $((RETRY_COUNT+1)) to install pwntools..."

apt-get install -y python3 python3-pip python3-dev git libssl-dev libffi-dev build-essential
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pwntools

# 检查安装是否成功
if [ $? -eq 0 ]; then
INSTALL_SUCCESS=true
else
RETRY_COUNT=$((RETRY_COUNT+1))
fi
done

if [ "$INSTALL_SUCCESS" = true ]; then
echo "pwntools installed successfully!"
else
echo "Failed to install pwntools after $MAX_RETRIES attempts."
fi

MAX_RETRIES=3
INSTALL_SUCCESS=false
RETRY_COUNT=0

# 安装pwndbg
while....

另外一种方式

​ 只需要定义一个变量, 而且代码量少了很多

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# 定义变量
MAX_RETRY=3

# 更新apt源
for (( i=1; i<=$MAX_RETRY; i++ )); do
if sudo apt update; then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "更新apt源时出现错误"
exit 1
fi
echo "更新apt源失败,正在进行第$i次重试..."
sleep 1
done

# 安装常用工具
for (( i=1; i<=$MAX_RETRY; i++ )); do
if xxxxxxxxxxx; then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装常用工具时出现错误"
exit 1
fi
echo "安装常用工具失败,正在进行第$i次重试..."
sleep 1
done

定好模版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash

# 定义变量
MAX_RETRY=3


# 安装常用工具
for (( i=1; i<=$MAX_RETRY; i++ )); do
if xxxxxxxxxxx; then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装常用工具时出现错误"
exit 1
fi
echo "安装常用工具失败,正在进行第$i次重试..."
sleep 1
done

套上!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#! /bin/bash

mkdir /ctfpwntools
cd /ctfpwntools

# 定义变量
MAX_RETRY=3

# 必要的更新、安装常用工具
for (( i=1; i<=$MAX_RETRY; i++ )); do
if (apt-get update;apt-get -y install python3 python3-pip python3-dev git libssl-dev libffi-dev build-essential git vim gdb strace ltrace socat netcat); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "更新、安装常用工具时出现错误"
exit 1
fi
echo "更新、安装常用工具失败,正在进行第$i次重试..."
sleep 1
done

# 安装pwntools
for (( i=1; i<=$MAX_RETRY; i++ )); do
if (python3 -m pip install --upgrade pip;python3 -m pip install --upgrade pwntools); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装pwntools时出现错误"
exit 1
fi
echo "安装pwntools失败,正在进行第$i次重试..."
sleep 1
done


# 安装pwndbg

for (( i=1; i<=$MAX_RETRY; i++ )); do
if (git clone https://github.com/pwndbg/pwndbg;cd pwndbg;./setup.sh;echo "source /ctfpwntools/pwndbg/gdbinit.py" >> ~/.gdbinit;cd ..); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装pwndbg时出现错误"
exit 1
fi
echo "安装pwndbg失败,正在进行第$i次重试..."
sleep 1
done



# 安装glibc-all-in-one
for (( i=1; i<=$MAX_RETRY; i++ )); do
if (git clone https://github.com/matrix1001/glibc-all-in-one.git;cd glibc-all-in-one/;python3 update_list;cd ..); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装glibc-all-in-one时出现错误"
exit 1
fi
echo "安装glibc-all-in-one失败,正在进行第$i次重试..."
sleep 1
done


# 安装ROPgadget
for (( i=1; i<=$MAX_RETRY; i++ )); do
if (pip install capstone;git clone https://github.com/JonathanSalwan/ROPgadget.git;cd ROPgadget;sudo python3 setup.py install;cd ..); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装ROPgadget时出现错误"
exit 1
fi
echo "安装ROPgadget失败,正在进行第$i次重试..."
sleep 1
done


# one_gadget
# 32位libc


for (( i=1; i<=$MAX_RETRY; i++ )); do
if (apt -y install ruby;gem install one_gadget;dpkg --add-architecture i386;apt-get -y install libc6:i386 libgtk2.0-0:i386); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装one_gadget时出现错误"
exit 1
fi
echo "安装one_gadget失败,正在进行第$i次重试..."
sleep 1
done

# LibcSearcher
for (( i=1; i<=$MAX_RETRY; i++ )); do
if (git clone https://github.com/lieanu/LibcSearcher.git;cd LibcSearcher;python3 setup.py develop;cd ..); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装LibcSearcher时出现错误"
exit 1
fi
echo "安装LibcSearcher失败,正在进行第$i次重试..."
sleep 1
done


# patchelf
for (( i=1; i<=$MAX_RETRY; i++ )); do
if (apt-get install autoconf automake libtool;git clone https://github.com/NixOS/patchelf.git;cd patchelf;./bootstrap.sh;./configure;make;make check;make install;cd ..); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装patchelf时出现错误"
exit 1
fi
echo "安装patchelf失败,正在进行第$i次重试..."
sleep 1
done



## seccomp //安装失败
## ruby版本会和上面那个onegadget冲突吗??

for (( i=1; i<=$MAX_RETRY; i++ )); do
if (add-apt-repository ppa:brightbox/ruby-ng;apt-get install ruby2.6 ruby2.6-dev ;gem install seccomp-tools); then
break
fi
if [ $i -eq $MAX_RETRY ]; then
echo "安装seccomp时出现错误"
exit 1
fi
echo "安装seccomp失败,正在进行第$i次重试..."
sleep 1
done




问题

pip还是pip3呢

还有一些小问题、以及还有其他有用工具没安装

参考

https://blog.csdn.net/mandiheyanyu/article/details/122455348

安装工具参考: https://blingblingxuanxuan.github.io/2020/02/23/paper/