Creating a Web Bug

Home / Creating a Web Bug

Creating a Web Bug

December 11, 2015 | Article | No Comments

Web Bug is a simple graphic on a web site or in a email that collects information about the user who is visiting the website or who is reading the email. In early day of internet, it is often used for several purpose.

People often say to look for graphics which are 1×1 pixel big to identify web bug. However even a normal graphic can be a Web Bug.

In this article we will discuss about how to create such a web bug.

For do such purpose, we use:

  1. Apache Web server (either self-hosted or host it on other location) which allows .htaccess files
  2. PHP scripts enabled with GD library installed.

Steps

Create a new folder, something like “webbug” folder.

Create a “.htaccess” file which contains following line on “webbug” folder :

ForceType application/x-httpd-php

It tells the server to treat everything in this folder as php file (even with no or different extension). So “randompic.jpg” will be treated like a php file and not like a jpg file.

Put a jpg file (the one which is going to be the Web Bug later) into the “webbug” folder. Let say “xathrya.jpg”

Create a new file and save it as (let say) “sig.jpg” on “webbug” folder. This is a file with all the php code. Copy following code as content of “sig.jpg”.

<?php
header("Content-Type: image/jpeg");

// This is used to log the IP of people viewed the site with the picture.
if ($_SERVER["HTTP_X_FORWARDED_FOR"]){
   $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}else{
   $ip = $_SERVER["REMOTE_ADDR"];
}
$ip = "IP: ".$ip."<br />";

// Open file stream to write
$hfile = fopen("data.txt", "w+");
fwrite($hfile, $ip);
fclose($hfile);

// Open image as stream and write it as response.
$BGImage = imagecreatefromjpeg("sigpic.jpg");
imagejpeg($BGImage);
imagedestroy($BGImage);
?>

The snipet there will be treated as a jpg file by browser, after we write whatever to log information. This simple script will log user IP address and in the end present a JPEG data so the image gets shown and nobody has a clue that something else is going between.

What Web Bug capable of? Many things, just like common PHP scripts do. However, this is interesting as people might not know what happen before they do inspection.

About Author

about author

xathrya

A man who is obsessed to low level technology.

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial