<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Artur</title>
    <description>The latest articles on Forem by Artur (@focarica).</description>
    <link>https://forem.com/focarica</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3385070%2F3fa47a4e-a655-4be1-9874-a52a38794b9c.jpeg</url>
      <title>Forem: Artur</title>
      <link>https://forem.com/focarica</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/focarica"/>
    <language>en</language>
    <item>
      <title>ICMP Spoofing with Scapy: Responding to Pings as a Fake IP</title>
      <dc:creator>Artur</dc:creator>
      <pubDate>Wed, 30 Jul 2025 01:59:20 +0000</pubDate>
      <link>https://forem.com/focarica/icmp-spoofing-with-scapy-responding-to-pings-as-a-fake-ip-82o</link>
      <guid>https://forem.com/focarica/icmp-spoofing-with-scapy-responding-to-pings-as-a-fake-ip-82o</guid>
      <description>&lt;p&gt;Spoofing is a commonly used technique in cyberattacks, especially in scenarios like &lt;strong&gt;email spoofing&lt;/strong&gt;, &lt;strong&gt;SMS spoofing&lt;/strong&gt;, and &lt;strong&gt;ARP poisoning&lt;/strong&gt;. In this article, I’ll share a small lab I built using Scapy to explore spoofing at a lower level: the network layer, using ICMP packets.&lt;/p&gt;

&lt;p&gt;The core idea is simple:&lt;br&gt;
&lt;em&gt;When a host sends a ping to a nonexistent IP address, the script intercepts the ICMP Echo Request and replies as if it were the intended destination.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Concepts
&lt;/h2&gt;

&lt;p&gt;Before diving into the code, let’s briefly go over the key concepts used in this project:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;ARP Spoofing&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This technique involves tricking a host’s ARP table by claiming that a specific IP is associated with the attacker’s MAC address. As a result, all traffic to that IP gets redirected to the attacker.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;ICMP Spoofing&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once ARP poisoning is successful, ICMP packets (ping requests) will reach the attacker. The attacker can then respond with spoofed ICMP Echo Replies, pretending to be the targeted IP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find the full source code on GitHub: &lt;a href="https://github.com/focarica/ICMP-Spoof" rel="noopener noreferrer"&gt;ICMP-Spoof&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interesting Details
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Using &lt;code&gt;icmp[icmptype]=8&lt;/code&gt; as a BPF Filter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This BPF filter captures only ICMP Echo Requests (ping). It avoids processing unrelated ICMP messages, like Echo Replies or Destination Unreachables.&lt;/p&gt;

&lt;p&gt;Alternative filters include:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;icmp — all ICMP packets

icmp[icmptype]=0 — only Echo Replies

icmp[icmptype]=8 — only Echo Requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Using the ARP Destination IP as ICMP Source&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our attacker doesn’t know in advance which IP will be pinged. Instead, the script listens for ARP requests and captures the IP the victim is trying to reach:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ip_src = pkt[ARP].psrc&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then it sends an ARP reply claiming to own that IP and saves it. When the ICMP Echo Request arrives, the script responds using that IP as the source.&lt;/p&gt;

&lt;p&gt;This dynamic behavior makes the tool useful for demonstrating spoofing against arbitrary targets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up the Lab
&lt;/h2&gt;

&lt;p&gt;To test this safely, use two virtual machines connected via an internal or bridged network in VirtualBox, VMware, or similar hypervisor.&lt;/p&gt;

&lt;p&gt;Example setup:&lt;br&gt;
Create an attacker machine with some IP like 10.9.0.10 and runs the script with another machine, the victim with IP 10.9.0.1 and run &lt;code&gt;ping 10.9.0.99&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This IP does not exist, but the script will respond as if it does.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learn
&lt;/h2&gt;

&lt;p&gt;Although this lab is simple, it reveals several fundamental insights about how real-world networks behave:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A hands-on understanding of low-level packet structures and protocols&lt;/li&gt;
&lt;li&gt;How ARP caches can be manipulated through spoofed replies&lt;/li&gt;
&lt;li&gt;The stateless nature of ICMP and its trust in source IPs&lt;/li&gt;
&lt;li&gt;How systems and routers react to unexpected traffic, including ICMP Redirects and Host Unreachables&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cybersecurity</category>
      <category>network</category>
      <category>beginners</category>
      <category>python</category>
    </item>
  </channel>
</rss>
