1

Almost all of us have heard of services like spypig . I was wondering how do they track client's IP when an image from their server get loaded. To do the same I made an aspx page with Response.ContentType = "image/png" but for this my link goes as

www.something.com/imagePage.aspx?id=rndmval

Is there any method by which whenever an image from my server say "mysite.com/images/me.gif" gets loaded on a system i get notified with the ip of that system? Its similar to monitoring an image. I like the way spypig works, it can monitor an image whenever it gets loaded on any browser. Does anybody know how do they do that???

Amit
  • 427
  • 4
  • 16
  • Um, `Request.ServerVariables("REMOTE_ADDR")`? – J. K. Oct 28 '12 at 11:44
  • yep.. just figured out from the docs :) – redShadow Oct 28 '12 at 11:49
  • not the page Ian. I wanna track a single image. A jpg image that gets loaded on any email or webpage and returns me the client's details onLoad. – Amit Oct 28 '12 at 11:50
  • @Amit you have to have the image stored on you server in order to track the request; there's no such way as "magic" images that run some code, or so.. – redShadow Oct 28 '12 at 11:51
  • (a part of course from some overflow vulnerabilities that have come up in the past, but I wouldn't use them to provide a service.. :P) – redShadow Oct 28 '12 at 11:52
  • @redShadow: I have seen some php vulnerabilities in which they tried hiding scripts in a gif image. I tried that too. I concatenated script.js with image.jpg and img.jpg as resultant file. Image loads fine but it never executes the script. Have a look at spypig I wanna know how did they do it – Amit Oct 28 '12 at 12:03
  • 1
    ...such vulnerabilities are ways to execute code *on the server side*, not *on the client side*.. anyways, you cannot rely on such things, as they might (and should!) get fixed one day.. – redShadow Oct 28 '12 at 12:07
  • @redShadow: word... but does this mean that we cant monitor a file? – Amit Oct 28 '12 at 12:12

2 Answers2

4

You get the request, extract the IP address of the client from the request (not sure how to do that in ASP, but there certainly is a way to do that) and store it in a database / send an e-mail / whatever..

No need to set Content-type to image/png, it's just a nicer way to tell the browser, who is expecting an image, "here it is your image", but unless you return an actual 1x1 PNG image, it doesn't make much sense.

Update

The IP address should be contained in:

Request.ServerVariables("remote_addr")

If you want a "clean" url, such as http://example.com/path/to/image.gif, you have to do something webserver-side; one common hack used in PHP is to make the web server "rewrite" a request to /path/to/non-existent/file to something like /path/to/my/script.php?path=/path/to/non-existent/file, not sure how to do that with ASP/IIS though...

Update: How does spypig work

They give you an "image to be put in emails", that is, an <img> tag with a src="" pointing to some page on their server, containing a unique identifier in its name, for example:

http://example.com/track-user.asp?id=ABCD12345678

Once the user opens the email containing the image (beware that most email programs require the user to click "load external content" before images are actually loaded -- that is, an anti-tracking measure), a request is sent to the server which stores somewhere a record containing the id, date, ip address and any other interesting information.

Knowing who you sent a certain id to, you can track which is the e-mail that got opened.

(one common trick to get the user click on "load external images", is to send an e-mail that heavily require images to display properly, so the user is encouraged to load them -- and get tracked).

redShadow
  • 6,687
  • 2
  • 31
  • 34
  • @redshow: the aspx page works fine and I have returned an image too. But i dont want to use an aspx or any page. I want to let anyone copy an image from my site and simply paste it on an email or any web document. Whenever this image gets loaded by anyone I should get client's details. Its similar to what google analytics does but its with an image not with a webpage. – Amit Oct 28 '12 at 11:46
  • 1
    You don't copy an image, you copy a HTML `` tag with the `src` attribute set to your ASP page. The page then logs client info and returns a 1x1px image just so that something is returned. – J. K. Oct 28 '12 at 11:49
  • @IanKuca i agree. but what if i want to write instead of some.ASPX? – Amit Oct 28 '12 at 12:09
  • I have never worked with IIS/ASP but there is surely a similar rewrite engine to mod_rewrite for Apache. You need to map the image path to your ASP script. For Apache+PHP: `RewriteRule /image.jpg /script.php` – J. K. Oct 28 '12 at 12:12
0

Looking quickly at this spypig.com it seems that when you create an image it's given a unique ID. This ID is then stored in the database and when someone later enters this image, the system can match this unique ID with e-mail address that has to be notified.

Tracking IPs is actually much simpler. HTTP works on top of TCP/IP so you always know what is the address of the client (it might be a firewall/NAT/spoofed address though).

In ASP this might be useful: How to get a user's client IP address in ASP.NET? but virtually any HTTP server-side technology will give you access to this information. Look how much my web browser sends when loading an image (any e-mail client will provide similar information):

GET /rndmVal/img.gif HTTP/1.1
User-Agent: Opera/9.80 (X11; Linux i686; U; pl) Presto/2.10.229 Version/11.64
Host: localhost:8080
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: pl-PL,pl;q=0.9,en;q=0.8
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Connection: Keep-Alive

The IP address of client computer can be obtained from TCP/IP connection.

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • @Tomsaz: that was a helping reply but i still cant understand how does merely copying to an email returns the client's detail. I mean we are loading an image not a script. There must be a monitoring mechanism thats tracking the image load.... – Amit Oct 28 '12 at 12:06
  • @Amit: I haven't used that service (what do you mean by "client's details"?) but when e-mail client opens "spypig.com/rndmVal/img.gif" the spypig.com server can retrieve your e-mail address and subject that you provided when generating the image by fetching it from database using `rndmVal` key. – Tomasz Nurkiewicz Oct 28 '12 at 12:11
  • @Tomsaz: the way it works is the same. rndmVal is my unique identifier in their db. The image when loaded gives clients IP. when someone opens an email i get notified with the IP os and browser of receiver. I can do it with an aspx page. What I am interested in is that image. The image gives the ip to spypig server which then mails it to me. I just wanna know 'how?' How does image load returns client's IP – Amit Oct 28 '12 at 12:18
  • @Amit: see my update. Any e-mail client or web browser will provide plenty of information when accessing this embedded image. Web server/aspx page is free to access and parse them – Tomasz Nurkiewicz Oct 28 '12 at 12:31