Jan 20, 2023

Ethical hacking: Hassle free logging of IP address of any person

Aim

In this article we will write static HTML and javascript client side code to log the IP address of the person just by sending him the web page link.

Introduction

PostMail: used to send email using javascript.
IpApi.co: used to get IP address and geolocation details at client side javascript

First Let's create simple jQuery plugin to send GET the CORS resource hosted at ipapi.com.
With recent version of jQuery it forces us to follow CORS policy so I am using plain JavaScript

jQuery.getCORS = function (source, func) {
    var xmlHttpRequestObject;
    if (window.XMLHttpRequest) {
        xmlHttpRequestObject = new XMLHttpRequest();
        if (xmlHttpRequestObject != null) {
            var sUrl = source;
            xmlHttpRequestObject.open("GET", sUrl, true);
            xmlHttpRequestObject.onreadystatechange = function () {
                func(xmlHttpRequestObject.responseText);
            };
            xmlHttpRequestObject.send();
        } else {
            func("Error creating XmlHttpRequest object. Client is not CORS enabled");
        }
    }
};
 

Following code retrieves the IP address of the user at client side

$.getCORS('https://ipapi.co/json/', function (data) {
	console.log(data);
};
 
For example following is response from ipapi for 8.8.8.8 google ip address:

Now lets get API key from PostMail
Go to the site https://postmail.invotes.com/, enter your email address and after submission you will get link in the email.

POST request to send email from javascript using postmail API

var data = {
	"access_token": "PostMail Access Token Here"
};

data['subject'] = "Send email from javascript";
data['text'] = "This is test email";

$.post('https://postmail.invotes.com/send',
    data,
    function () {
        //success
    }
).fail(function () {
    //error
});


Final version:


    
    

    
Loading...
]]>

This code is available on github, editable at stackblitz⚡️

References

How to send an email from JavaScript: https://stackoverflow.com/a/36656479/223752
PostMail: https://postmail.invotes.com/
IP geolocation API: https://ipapi.co

Note: I am not affiliated with PostMail or ipapi.co

No comments:

Post a Comment

Be the first to comment on this post.