ads

Understanding Attacks Using Python (Python for Hackers Part - 11)

Hacking is not all about launching attacks – understanding how black hat hackers launch target and penetrate their target systems will make you understand how you can use your new found knowledge to prevent your own system from being vulnerable to them.


Knowing User Locations Out of Tweets


If you have been using Twitter, you may think that you are tweeting your updates from sheer randomness; however, the truth is that you are following an informal formula for the tweets that you compose. Generally, this formula includes another Twitter user’s name which tells to whom your tweet is directed to, the text of your tweet, and your choice of hash tag. There are other data included in your tweet, which may not be visible in the body of your tweet, such as an image that you want to share or a location. 


To a hacker, all the information in your tweet contains something that will be important in writing an attack – when you think about it, you are giving away information about the person that you are interested in, links that you and your friend are likely to be interested in, and trends that you might want to learn about. The pictures, especially an image of a location, become added details to a user’s profile, which for example may indicate where a targeted person is likely to go to eat breakfast.

If you want to get details anonymously to retrieve all these information, you can use the following code:


Now, you can test this script by creating a list of cities that host major league teams. After that you can scrape Twitter accounts for Washington Nationals and the Boston Red Sox. Your script will look like this:


When your script returns with the above results, you are likely to deduce that the these teams are tweeting live from where they are. From this output, you may deduce that the Red Sox are playing in Toronto, while the Nationals are in Denver.

Matching an IP Address to a Physical Location


Most of the time, people are willing to post what is on their mind on social media sites, or perform attacks that they find using online tools that they can download, thinking that they will never have to face the consequences of their actions. While most bullheaded yet inexperienced hackers and online trolls think that they can hide behind a fake account to conceal their identity, you can prove that these people are not as anonymous as they think they are. In fact, there are several ways to use libraries and third-party modules in Python to unmask the location and identity of a user based on his or her IP address.

For example, you suspect that your system is being targeted by another hacker and you notice that your open ports are being sniffed by a particular IP address. What you will want to do once you realize this potential attack is to identify that IP address’ location and report it to the authorities. Python can help you do that using a script that is similar to what is going to be discussed in this section.


In this example, you will be using the freely available database that can be found in
http://www.maxmind.com/app/geolitecity. Using this free database, you will aim to write a code that will match the IP addresses found on their list to cities. To do that, download the free database, decompress it, and send it to the location /opt/GeoIP/Geo.dat.

Once you are able to download the GeoCityLite database, you will be able to analyze the IP addresses down to locating the country name, state, postal code, and a general longitude and latitude. To make the job easier, you can use a Python library created to analyze this database.

When you run this script, you will be able to see data that looks like this:

Post a Comment

0 Comments