0
Home  ›  Python

Melakukan Spoofing IP Address Menggunakan Python


Hallo all kali ini kita akan membahas cara melakukan spoofing dengan menggunakan bahasa pemograman python. Spoofing merupakan tindakan seseorang dalam memalsukan alamat IP dalam paket jaringan untuk menipu sipenerima. Teknik ini sering skeali di gunakan dalam ceybercrime seperti spoofing IP, serangan Man-in-the-middle, dan serangan Denial of Service (DoS) untuk menyamarkan identitas asli pengirim dan berpotensi menghindari tindakan keamanan.


Di dalam tutorial ini permintaan akan dikirim dari mesin Kali Linux ke host Metasploitable, menampilkan penerapan praktis dari IP sumber palsu. Ping adalah alat utilitas jaringan yang mengirimkan pesan Permintaan Gema Internet Control Message Protocol (ICMP) ke perangkat target dan menunggu Balasan Gema. 

Metasploitable adalah mesin virtual yang sengaja rentan yang digunakan oleh para profesional keamanan dan peretas etis untuk tujuan pengujian dan pendidikan. Ini telah dikonfigurasi sebelumnya dengan berbagai kerentanan dan kelemahan, memungkinkan pengguna untuk mempraktikkan pengujian penetrasi dan penilaian keamanan dalam lingkungan yang terkendali. Dalam tutorial penebak kata sandi, kami menunjukkan cara mengaturnya.
$ pip3 install scapy faker colorama
Untuk windows kamu bisa menggunakan perintah
$ pip3 install scapy faker colorama
Colorama adalah pustaka Python yang menyederhanakan pemformatan teks terminal dengan mengizinkan penggunaan kode escape ANSI untuk keluaran berwarna pada sistem berbasis Windows dan Unix.
import sys
from scapy.all import sr, IP, ICMP
from faker import Faker
from colorama import Fore, init
  1. import sys: Mengimpor modul sys, menyediakan akses ke parameter dan fungsi spesifik sistem.
  2. from scapy.all import sr, IP, ICMP: Memanfaatkan Scapy, perpustakaan manipulasi paket untuk mengimpor fungsi untuk mengirim dan menerima paket serta konstruksi paket IP dan ICMP.
  3. from faker import Faker: Menggabungkan Fakerperpustakaan, memfasilitasi pembuatan data palsu, termasuk alamat IP.
  4. from colorama import Fore, init: Mengintegrasikan colorama, perpustakaan Python untuk memperkenalkan keluaran teks berwarna di terminal. Modul ini Forememungkinkan pengaturan warna latar depan teks, dan initmenginisialisasi colorama untuk kompatibilitas lintas platform.
Selanjutnya, kita akan menginisialisasi coloramadan Faker, lalu membuat fungsi untuk menghasilkan alamat IPv4 acak untuk kita:
# Initialize colorama for colored console output
init()
# Create a Faker object for generating fake data
fake = Faker()

# Function to generate a fake IPv4 address
def generate_fake_ip():
   return fake.ipv4()
Kemudian buat 2 buah fungsi Salah satunya adalah membuat dan mengirim paket kita, dan yang lainnya adalah menampilkan ringkasan paket. Yang pada dasarnya adalah versi ringkasan informasi paket:
# Function to craft and send an ICMP packet.
def craft_and_send_packet(source_ip, destination_ip):
   # Craft an ICMP packet with the specified source and destination IP.
   packet = IP(src=source_ip, dst=destination_ip) / ICMP()
   # Send and receive the packet with a timeout.
   answers, _ = sr(packet, verbose=0, timeout=5)
   return answers

# Function to display a summary of the sent and received packets.
def display_packet_summary(sent, received):
   print(f"{Fore.GREEN}[+] Sent Packet: {sent.summary()}\n")
   print(f"{Fore.MAGENTA}[+] Response: {received.summary()}")
Kemudian tambahkan bagian utama program.
# Check if the correct number of command-line arguments is provided
if len(sys.argv) != 2:
   print(f"{Fore.RED}[-] Error! {Fore.GREEN} Please run as: {sys.argv[0]} ")
   sys.exit(1)

# Retrieve the destination IP from the command-line arguments
destination_ip = sys.argv[1]
# Generate a fake source IP
source_ip = generate_fake_ip()

# Craft and send the packet, and receive the response
answers = craft_and_send_packet(source_ip, destination_ip)

# Display the packet summary for each sent and received pair
for sent, received in answers:
   display_packet_summary(sent, received)

Lalu save, dan untuk menjalankan codenya gunakan perintah.
$ python3 ip_spoofer.py 192.168.134.129
Untuk code fullnya seperti di bawah ini.
# Import the neccasary modules.
import sys
from scapy.all import sr, IP, ICMP
from faker import Faker
from colorama import Fore, init

# Initialize colorama for colored console output.
init()
# Create a Faker object for generating fake data.
fake = Faker()

# Function to generate a fake IPv4 address.
def generate_fake_ip():
    return fake.ipv4()

# Function to craft and send an ICMP packet.
def craft_and_send_packet(source_ip, destination_ip):
    # Craft an ICMP packet with the specified source and destination IP.
    packet = IP(src=source_ip, dst=destination_ip) / ICMP()
    # Send and receive the packet with a timeout.
    answers, _ = sr(packet, verbose=0, timeout=5)
    return answers

# Function to display a summary of the sent and received packets.
def display_packet_summary(sent, received):
    print(f"{Fore.GREEN}[+] Sent Packet: {sent.summary()}\n")
    print(f"{Fore.MAGENTA}[+] Response: {received.summary()}")

# Check if the correct number of command-line arguments is provided.
if len(sys.argv) != 2:
    print(f"{Fore.RED}[-] Error! {Fore.GREEN} Please run as: {sys.argv[0]} <dst_ip>")
    sys.exit(1)

# Retrieve the destination IP from the command-line arguments.
destination_ip = sys.argv[1]
# Generate a fake source IP.
source_ip = generate_fake_ip()
# Craft and send the packet, and receive the response.
answers = craft_and_send_packet(source_ip, destination_ip)
# Display the packet summary for each sent and received pair.
for sent, received in answers:
    display_packet_summary(sent, received)
./X3NUX
Mereka teralu banyak mengusik, maka bunuh dan dan matilah sekarang juga!!!!
Post a Comment
Search
Menu
Theme
Share
Additional JS