Showing posts with label Recon-ng. Show all posts
Showing posts with label Recon-ng. Show all posts

Advanced Reconnaissance with Recon-ng (Part IV)

Now the goal is to gather information about the network infrastructure and not about the users.

Network reconnaissance

  • Create a new workspace

workspace create SANS

  • Now you have two workspaces:

Listing workspaces

  • To insert the company, you can use an alternative way:

db insert companies SANS~SANS Institute

Inserting company name and description

  • To insert the domain, type

db insert domains sans.org

  • And repeat to add a second domain.


Inserting domain names

Now we are going to use different modules because we want to reach a different goal.

  • Let’s start trying to get the Private Enterprise Numbers (PEN)

Using the pen module

This doesn’t seem to be really useful. Let’s delete all these new domains.

  • List the rows on the domains table and delete the useless ones

Deleting the useless domains

Let’s try to use the given domains to find hosts.

  • There are a number of modules capable of doing that:

Listing the "domains to hosts" modules

Not all of them return results for every scenario so I’ll just list the ones that produce something for the given domains:

Bing Hostname Enumerator

Running the Bing Hostname Enumerator module

Certificate Transparency Search

Running the Certificate Transparency Search module

Google Hostname Enumerator

Running the Google Hostname Enumerator module

HackerTarget Lookup

Running the HackerTarget Lookup module

Mail eXchange (MX) and Sender Policy Framework (SPF) Record Retriever

Running the MX Record Retriever module

ThreatCrowd DNS lookup

Running the ThreatCrowd DNS lookup module

ThreatMiner DNS lookup

Running the ThreatMiner DNS lookup module

We can also try to brute force the discovery of new hosts. This is done using a provided wordlist and checking each new combination against the default DNS server.

  • Load the module and check the default options

Loading the brute_hosts module

As you can see, the application is using the file /root/.recon-ng/data/hostnames.txt as a source of strings to be added to the given domain name. You can use other files if you want to.

  • Check the ones available in /usr/share/wordlists

Listing the wordlists available in Kali Linux

  • Check the global options (recon-ng environment) to identify the configured DNS server

goptions list

Checking Recon-ng global options

The choice of the DNS server is important because you’ll probably be blocked before the end of the wordlist due to the excess number of requests.

DNS request being blocked

To change the DNS server you have to exit he current loaded module.

  • Just type:

back

  • Then set the proper option

options set NAMESERVER 1.1.1.1

Changing the DNS server

Run the module with the default configuration

Running the brute_hosts module

  • Maybe now is a good time to take a snapshot before moving on to the next set of modules

snapshots take

Taking a database snapshot

We have now 302 hosts but only two domains.

Let’s populate the domains table with info from the host table

  • Load and run the migrate_host module

Running the migrate_hosts module

As you can see, a number of useless domains are added to the database.

If you don’t like the results, load the previous database from the snapshot

  • List the available snapshots

snapshots list

Listing the snapshots

  • Load the desired snapshot

snapshots load <snapshot name>

Loading the last snapshot

Let’s try to use the “hosts to hosts” modules:

  • List them

Listing the host to hosts modules

Again, not all modules return useful information or can be used due to the lack of proper API keys

Hostname Resolver

Running the Hostname Resolver module

Reverse Resolver

Running the Reverse Resolver module

Now it’s time to evaluate the quality of the information gathered so far. In the previous post I showed how to query the database and how to clean the data.

In this case, try the following queries:

  • Let’s delete al hosts outside the desired domain

db query DELETE FROM hosts WHERE host NOT LIKE "%sans.org"

Deleting unwanted hosts

db query DELETE FROM hosts WHERE host LIKE "*%"

Deleting unwanted hosts

  • Let’s also delete the unwanted domains

db query DELETE FROM domains WHERE domain NOT LIKE "%sans.org"

Deleting unwanted domains

Repeating the use of the previously used “domain to hosts” modules will add another handful of hosts to the database.

There are many repeated entries in the hosts table. However, this is not conclusive because several services can run in the same host and due to the distributed nature of these services, the same service can have more than one IP address.

Let’s get additional info about each host

Geolocation via IPStack

Getting geographical info for each host

Open ports via Binary Edge

Getting info about open ports for each host

Open ports via Censys

Getting info about open ports for each host

Setting the options for the module

Final result: 494 hosts with 510 open ports. Nod bad Winking smile

All this information was gathered without any direct interacting with any of the target machines/domains.

If you decide to use the discovery or the exploitation modules be very careful before doing so because you will be in direct contact with the target machines and that is something that should always be done with the proper authorization.

Exporting and analyzing information

Lets’ export the information in html format

  • Load the proper module

Loading the html module and displaying the options

  • Setting the options

Setting the options for the module

  • Opening the output file

Opening the exported file

If you prefer, you can access all available data in recon-ng in a web-based user interface

  • Exit the application and type

recon-web

Starting recon-web reporting engine

Using the recon-web interface

The major advantage of this analytics engine is the possibility to access all workspaces easily and to have all the info very well organized.

Final conclusion: Recon-ng v5.0.1 is one of the best free tools currently available to conduct an initial analysis on a potential target. With more APIs the results will be even better.


Next post: Advanced Footprinting with Maltego (Part I)

Advanced Reconnaissance with Recon-ng (Part III)

Now is a good time to filter all those unwanted contacts from unwanted domains. This can be done using SQL statements on the SQLite database.

Filtering and cleaning data

  • Let’s see how many contacts we have from the united.com domain

db query SELECT email FROM contacts WHERE email LIKE “%@united.com”

Searching for contacts from the proper domain






Total contacts from the proper domain





  • But we also a lot of contacts from other domains

db query SELECT email FROM contacts WHERE email NOT LIKE “%@united.com”

Searching for contacts from wrong domains





Total contacts from the wrong domain






  • And some others don’t have an e-mail address

 db query SELECT email FROM contacts WHERE email IS NULL

Searching for contacts without e-mail




Total contacts without e-mail






  • Let’s delete all contacts from unwanted domains

db query DELETE FROM contacts WHERE email NOT LIKE “%@united.com”

Deleting the contacts from wrong domains

Let’s try to create email addresses for the contacts only having first and last names

  • This can be done using another specific module named mangle

modules load recon/contacts-contacts/mangle

Loading the mangle module

  • Set the proper module options

Setting the mangle options

The result is not perfect but it is better than before because now all contacts have an e-mail address.

Running the mangle module

Let’s now give some attention to the credentials table.

  • Let’s see how many credentials we have from unwanted domains

db query SELECT username FROM credentials WHERE username NOT LIKE “%@united.com”

Searching for credentials from wrong domains





Total credentials from wrong domains





  • Let’s delete all this useless information

db query DELETE FROM credentials WHERE username NOT LIKE “%@united.com”

Deleting the credentials from wrong domains

Let’s keep cleaning the information found.

  • Are there duplicates in the contacts table ?

db query SELECT first_name,last_name FROM contacts WHERE rowid NOT IN (SELECT MIN(rowid) FROM contacts GROUP BY email)

Searching for duplicate contacts

Total duplicate contacts









  • Let’s delete all duplicates

db query DELETE FROM contacts WHERE rowid NOT IN (SELECT MIN(rowid) FROM contacts GROUP BY email)

Deleting duplicate contacts

Let’s repeat the previous procedure for the credentials table

  • List duplicates

db query SELECT * FROM credentials WHERE rowid NOT IN (SELECT MIN(rowid) FROM credentials GROUP BY username)

Searching for duplicate credentials

Total duplicate credentials

  • Delete all duplicates

db query DELETE FROM credentials WHERE rowid NOT IN (SELECT MIN(rowid) FROM credentials GROUP BY username)

Deleting duplicate credentials

What about the profiles table?

  • List duplicates

db query SELECT * FROM profiles WHERE rowid NOT IN (SELECT MIN(rowid) FROM profiles GROUP BY username)

Searching for duplicate profiles

  • Do we have repeated urls?

db query SELECT * from profiles WHERE rowid NOT IN(SELECT MIN(rowid) from profiles GROUP BY url)

Searching for duplicate urls

  • But we have many repeated usernames pointing to different profiles. Those are all useless.

db query SELECT * from profiles WHERE rowid NOT IN(SELECT MIN(rowid) from profiles GROUP BY username)

Searching for duplicate usernames

Repeated usernames

  • Let’s delete all the repeated usernames

db query DELETE from profiles WHERE rowid NOT IN(SELECT MIN(rowid) from profiles GROUP BY username)

Deleting repeated usernames

  • Another analysis of the profiles shows that some are just referring to the country or language of the profile

db query SELECT * from profiles WHERE username LIKE "__" OR username LIKE "__-__"

Listing some more useless profiles

  • Remove these profiles

db query DELETE from profiles WHERE username LIKE "__" OR username LIKE "__-__"

Deleting useless profiles

It might be a good idea to make another database snapshot.

Finding additional data

Now we have a set of “clean” data but many records in the credentials table only have the hashes.

  • Search for credentials with no passwords.

db query SELECT * from credentials WHERE password ISNULL

Listing credentials without password

Total number of credentials without password

There is a module that tries to find known hashes.

  • Load the hashes module and run it

modules load recon/credentials-credentials/hashes_org

run

Finding additional passwords with the hashes module

  • If you want to focus on a specific group of hashes, set the module options

options set SOURCE query SELECT DISTINCT hash FROM credentials WHERE hash LIKE “__ <number of characters in the hash>_” AND password ISNULL AND leak LIKE “linkedin.com”

Selecting a group of hashes

The result will be the discovery of almost 200 additional passwords.

Initially, we used the bing_linkedin_cache module to find contacts. That is a “companies to contacts” module.

Now we can query Linkedin directly using the Bing API via the bing_linkedin_contacts module. And that is a “profiles to contacts” modules.

NOTE: Don’t forget to make a database snapshot!

  • Load and run the module

modules load recon/profiles-contacts/bing_linkedin_contacts

Getting contacts from Linkedin

This module will generate a lot of duplicate data because the new information will be inserted into new records. However, you will get a lot of information about the current positions of the company’s employees. The module might crash but that is because you will probably exceed the number of allowed queries with a free Bing API…

If you are skilled in SQL you can try to merge those records. Anyway, we already have a lot of profiles but they are limited to Linkedin. We can try to get some more from a wide variety of social media and popular websites.

It will be a very slow process because each individual profile will be tested against dozens of websites.

  • Load and run the profiler module

modules load recon/profiles-profiles/profiler

Running the profiler module

Once you are happy with the results, you can export them in multiple formats using one of the reporting modules.

Listing the reporting modules

Conclusion: With only a few free APIs, and using nothing but open-source data, it is possible to gather a huge amount of information.