<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/shodan-a-tool-for-security-and-market-research/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://aliarsalankazmi.github.io/posts/r/2017/11/21/shodan-r-market-security-research.html"> R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>So you have a knack for all things data, know a dozen different Machine Learning algorithms, are a skillful user of Big Data tools, and have started learning Deep Learning — not much else there is to Data Science, right?<br>
Well, I would submit that knowing ML algorithms and tools does not bring about the same Eureka Effect that, perhaps, a noteworthy change of data brings. Yes, we have Sound and Text data, but they are quite old too.<br>
How about getting data of publicly accessible Internet connected devices, their ports usage, certificates issued, etc. using a <strong>search engine</strong>: <a rel="nofollow" href="http://www.shodan.io/" target="_blank">Shodan</a>.</p>
<p>Shodan is no stranger to Security Analysts in the West, and perhaps, to an extent, to Data Scientists as well. It is less known amongst Security and Data Science professionals in the Middle East, however. Also, perhaps what is less known about Shodan is that it was originally developed as a Market Research tool. Shodan was developed by <a rel="nofollow" href="https://twitter.com/achillean?lang=en" target="_blank">John Matherly</a> as a search engine for Internet accessible devices. It has crawlers placed at various geological locations that crawl the internet, obtaining meta data of any web-enabled device. A quote from John’s book, <a rel="nofollow" href="https://leanpub.com/shodan" target="_blank">Complete Guide to Shodan</a>: “Web search engines, such as Google and Bing, are great for finding websites. But what if you’re interested in finding computers running a certain piece of software (such as Apache)? Or if you want to know which version of Microsoft IIS is the most popular? Or you want to see how many anonymous FTP servers there are? Maybe a new vulnerability came out and you want to see how many hosts it could infect? Traditional web search engines don’t let you answer those questions”.<br>
<strong>Shodan does!</strong></p>
<h3>Introductory Usage</h3>
<p>For a start: Let’s head to <a rel="nofollow" href="http://aliarsalankazmi.github.io/posts/r/2017/11/21/www.shodan.io" target="_blank">shodan</a> and see if we can find some publicly exposed cameras: often, we have non-technical people install camera devices that are also connected to the Internet. Although they do install them, they are unaware of how to safeguard their devices from unauthorised access.<br>
A simple query of <code>webcamxp country:&quot;GB&quot;</code> returns 36 results of webcams, some of which are publicly accessible. The following shows a webcam placed at some roundabout in the UK.</p>
<p><a rel="nofollow" href="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_post1_publicCam1.PNG" target="_blank"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_post1_publicCam1.PNG?w=456" data-recalc-dims="1"></a></p>
<p>But this was from the UK. Let us head over to the Middle East and try some other searches!</p>
<p>I know that Bitcoin is getting famous amongst residents of UAE; let’s try searching for Bitcoin on port 8333, which is <a rel="nofollow" href="https://bitcoin.org/en/full-node#network-configuration" target="_blank">designated</a> for running a Bitcoin client. We have two results, one in Dubai and one in Abu Dhabi.</p>
<p><a rel="nofollow" href="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_post1_bitcoinUAE1.PNG" target="_blank"><img src="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_post1_bitcoinUAE1.PNG?w=456" data-recalc-dims="1"></a></p>
<p>Interesting, isn’t it?<br>
But it is cumbersome to repeatedly go to the Web Interface, enter in our query, and then export the results (for the latter, you will have to become a member, which involves a minimal fee). Shodan does include a Command Line Interface, as well as an API. But since this blog is about all things <code>R</code>, I shall be utilising the <a rel="nofollow" href="https://github.com/hrbrmstr/shodan" target="_blank"><code>shodan</code></a> package developed by <a rel="nofollow" href="https://twitter.com/hrbrmstr" target="_blank">Bob Rudis</a>. I feel if <code>R</code> had a hall of fame, Bob deserves to be inlcuded in it for his valuable contributions.</p>
<h3>Using the R package for Shodan</h3>
<h4>MongoDBs</h4>
<p>Let’s do a quick search for Mongo DB in the UAE.</p>
<div>
<div>
<pre><code># Loading required packages

library(shodan)
library(data.table)
library(hrbrthemes)
library(tidyverse)
library(jsonlite)
library(extrafont)
library(viridis)

# Our search query:
uae_mongodb &lt;- shodan_search(&quot;product:mongodb country:AE&quot;)

uae_mongodb$matches %>% 
	select(as.numeric(version), org) %>% 
	add_column(city = uae_mongodb$matches$location$city) %>%
	mutate(vers = gsub(&quot;(^[[:digit:]]+\\.)[[:digit:]]+\\..+$&quot;, &quot;\\1&quot;, version)) %>%
	group_by(city, org, vers) %>%
	count() %>%
	ggplot(data = ., aes(x = vers, y = n)) +
	geom_col() +
	facet_wrap(~ city) +
	ggtitle(&quot;Counts of MongoDB instances per Version and City&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;MongoDB Version&quot;) +
	theme_ipsum()

</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g1.png" target="_blank"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g1.png?w=456" data-recalc-dims="1"></a></p>
<p>This was not so useful, as we only had 6 results from our search, with only 1 city identified (Dubai). One search result did not have any city information, but the IP address was available. Using Censys.io, it takes us to <a rel="nofollow" href="http://iot.emircom.com/#/intro" target="_blank">Emircom’s IoT Portal</a>. They have an 80MB database, and as per this <a rel="nofollow" href="https://www.shodan.io/host/213.42.180.195" target="_blank">view</a>, some additional parameters like ‘listDatabases’ also have a value to them (201 in this case). I don’t think they would like to expose such information to the general public.</p>
<p>Another one <a rel="nofollow" href="https://www.shodan.io/host/94.200.190.157" target="_blank">here</a> seems to be exposing some info too. Using Censys.io again, it seems this IP address is related to some Medical Imaging Information Management System.</p>
<p>A couple of quick notes here:</p>
<ol>
<li>
<p>I could have parsed this additional info using what is returned by <code>shodan</code> to <code>R</code>, but it seems the returned JSON does not follow conventions for a JSON format, so a conversion fails.</p>
</li>
<li>
<p>I think one can try to connect to the aforesaid MongoDB instances using a client. But unless one has an account with privileges, (s)he cannot perform actions on the database.</p>
</li>
</ol>
<p>This was more of a security perspective. How about some market research?</p>
<h4>Apache</h4>
<p>We can search for Apache without using any product filter. This will return any banners that contain the word Apache. I am going to search the first 100 pages, since I am just giving an overview.</p>
<div>
<div>
<pre><code>uae_apache &lt;- shodan_search(&quot;apache country:AE&quot;, page = 100)
rDf &lt;- uae_apache$matches %>% 
	select(version, org, port, product, domains) %>% 
	add_column(city = uae_apache$matches$location$city)

rDf %>% mutate(vers = gsub(&quot;(^[[:digit:]]+\\.[[:digit:]]+)\\..+$&quot;, &quot;\\1&quot;, version)) %>%
	group_by(vers, city) %>%
	count() %>%
	ggplot(data = ., aes(x = reorder(vers, n), y = n)) +
	geom_col() +
	facet_wrap(~ city) +
	ggtitle(&quot;Counts of Apache products per (trimmed) Version and City&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;Version Number&quot;) +
	theme_ipsum()

</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g2.png" target="_blank"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g2.png?w=456" data-recalc-dims="1"></a></p>
<p>Such info, albeit obtained from a sample of the results, could be useful for Market Research. We could also count instances of Apache against any organisations identified:</p>
<div>
<div>
<pre><code>rDf %>% group_by(org) %>%
	count() %>%
	ggplot(data = ., aes(x = reorder(org, n), y = n)) +
	geom_col() +
	coord_flip() +
	ggtitle(&quot;Counts of Apache products per Organisation&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;&quot;) +
	theme_ipsum()

</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g3.png" target="_blank"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g3.png?w=456" data-recalc-dims="1"></a></p>
<h4>IBM Server</h4>
<p>As another example, let’s search for IBM servers accessible to Shodan. I am just going to sample the results, rather than obtain all of them:</p>
<div>
<div>
<pre><code>uae_ibm &lt;- shodan_search(&quot;product:IBM country:AE&quot;)
rDf &lt;- uae_ibm$matches %>% 
	select(version, org, port, product, info, ip_str) %>% 
	add_column(city = uae_ibm$matches$location$city) %>%
	add_column(certif_issuerC = uae_ibm$matches$ssl$cert$issuer$C, 
		   certif_issuerO = uae_ibm$matches$ssl$cert$issuer$O, 
		   certif_obtainer = uae_ibm$matches$ssl$cert$subject$O)

rDf %>% mutate(vers = gsub(&quot;(^[[:digit:]]+\\.[[:digit:]]+)\\..+$&quot;, &quot;\\1&quot;, version)) %>%
	group_by(vers, product) %>%
	count() %>%
	ggplot(data = ., aes(x = reorder(vers, n), y = n)) +
	geom_col() +
	facet_wrap(~ product) +
	ggtitle(&quot;Counts of IBM products per (trimmed) Version&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;Version Number&quot;) +
	theme_ipsum()

</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g4.png" target="_blank"><img src="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g4.png?w=456" data-recalc-dims="1"></a></p>
<div>
<div>
<pre><code>rDf %>%
	group_by(org) %>%
	count() %>%
	ggplot(data = ., aes(x = reorder(org,n), y = n)) +
	geom_col() +
	coord_flip() +
	ggtitle(&quot;Counts of IBM products per Organisation&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;Organisation&quot;) +
	theme_ipsum()

</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g5.png" target="_blank"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g5.png?w=456" data-recalc-dims="1"></a></p>
<div>
<div>
<pre><code>rDf %>%
	select(certif_issuerO, certif_obtainer) %>%
	gather() %>%
	mutate(certif = ifelse(key == &quot;certif_issuerO&quot;, &quot;Certificate Issuer&quot;, &quot;Certificate Obtainer&quot;)) %>%
	group_by(certif, value) %>%
	summarise(counts = n()) %>%
	ggplot(data = ., aes(x = reorder(value, counts), y = counts)) + 
	geom_col() +
	coord_flip() +
	ggtitle(&quot;Counts of Certificate Owners and Issuers for IBM products in the UAE&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;&quot;) +
	facet_wrap(~ certif, ncol = 1, scales = &quot;free&quot;) +
	theme_ipsum()


</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g6.png" target="_blank"><img src="https://i1.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g6.png?w=456" data-recalc-dims="1"></a></p>
<h4>Industrial Control Systems (ICS)</h4>
<p>Let’s try searching for IoT devices in the UAE.</p>
<div>
<div>
<pre><code>uae_ics &lt;- shodan_search(&quot;category:ics country:AE&quot;)
rDf &lt;- uae_ics$matches %>% 
	select(version, org, port, product, devicetype, os, isp, ip_str) %>% 
	add_column(city = uae_ics$matches$location$city)

rDf %>% group_by(product) %>%
	count() %>%
	ggplot(data = ., aes(x = reorder(product, n), y = n)) +
	geom_col() +
	coord_flip() +
	ggtitle(&quot;Counts of ICS products in the UAE&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;Products&quot;) +
	theme_ipsum()
</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g7.png" target="_blank"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g7.png?w=456" data-recalc-dims="1"></a></p>
<div>
<div>
<pre><code>rDf %>% group_by(org) %>%
	count() %>%
	filter(!is.na(org)) %>%
	ggplot(data = ., aes(x = reorder(org, n), y = n)) +
	geom_col() +
	coord_flip() +
	ggtitle(&quot;Counts of ICS Products used by various Orgs in the UAE&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Count of ICS Products&quot;, x = &quot;Organisation&quot;) +
	theme_ipsum()

</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g8.png" target="_blank"><img src="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g8.png?w=456" data-recalc-dims="1"></a></p>
<p>In case you are wondering, Niagara Fox and Lantronix are IoT platforms that enable machines/devices to speak to each other seamlessly for purposes such as building automation, smart cities, etc. <br>
We also see some well-known organisations; let’s try checking the IP address of AVAST software. Plugging the IP address into <a rel="nofollow" href="https://www.ripe.net/" target="_blank">RIPE</a>, leads us to Holborn, London. But the port that was accessed by Shodan for AVAST was 44818, which is used for EtherNet, and I am unsure if this should be of concern.</p>
<h4>Checking Hotels</h4>
<div>
<div>
<pre><code>uae_hotels &lt;- shodan_search(&quot;org:Hotel country:AE&quot;)
rDf &lt;- uae_hotels$matches %>% 
	select(version, org, port, product, devicetype, os, isp, ip_str) %>% 
	add_column(city = uae_hotels$matches$location$city)

rDf %>% group_by(org) %>%
	count() %>%
	filter(!is.na(org)) %>%
	ggplot(data = ., aes(x = reorder(org, n), y = n)) +
	geom_col() +
	coord_flip() +
	ggtitle(&quot;Counts of Various Products used by various Hotels in the UAE&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Count of Various Products&quot;, x = &quot;Hotels&quot;) +
	theme_ipsum()


</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g9.png" target="_blank"><img src="https://i0.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g9.png?w=456" data-recalc-dims="1"></a></p>
<p>So, of these, let’s try to see what ports are being run/used at the Conference Palace and the Shangri-La Hotels.</p>
<div>
<div>
<pre><code>rDf %>% filter(org %in% c(&quot;Conference Palace Hotel&quot;, &quot;Shangri-La Hotel&quot;)) %>%
	group_by(org, port) %>%
	count() %>%
	filter(!is.na(org)) %>%
	ggplot(data = ., aes(x = reorder(port, n), y = n)) +
	geom_col() +
	coord_flip() +
	facet_wrap(~ org) +
	ggtitle(&quot;Counts of Various Ports used by Conference and Shangri-La Hotels in the UAE&quot;, 
		subtitle = &quot;Graph is based on a sample of data&quot;) +
	labs(y = &quot;Counts&quot;, x = &quot;Ports&quot;) +
	theme_ipsum()
</code></pre>
</div>
</div>
<p><a rel="nofollow" href="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g10.png" target="_blank"><img src="https://i2.wp.com/aliarsalankazmi.github.io/blog_DA/assets/img/shodan_g10.png?w=456" data-recalc-dims="1"></a></p>
<p>We see, interestingly, there is not an overlap in the ports being used at the two hotels. We also see a good amount of Port 179 usage at the Conference Palace Hotel. According to <a rel="nofollow" href="https://isc.sans.edu/forums/diary/Cyber+Security+Awareness+Month+Day+23+port+179+TCP+Border+Gateway+Protocol/7435/" target="_blank">this link</a>, it may be advisable not to rely on the said port. We also see Port 8008 being used: this is for Chromecast purposes.</p>
<p>For the Shangri-La, we see little data, but one of the ports which caught my attention is 1440, for Sonos. Apparently, this is a <a rel="nofollow" href="https://www.sonos.com/en-gb/system" target="_blank">Home Wireless Sound system</a>.</p>
<h4>Conclusion</h4>
<p>We have literally had a glimpse of the capabilities and usage of Shodan for Security and Market Research, and as it is obvious, Shodan’s use as a Market Research tool is very promising. That Shodan is useful for Security Research is, I think, a side-effect. Nonetheless, it is not so simple to use Shodan for Market Research, and this is because unlike in other fields where application of Data Science/Mining requires primarily a decent knowledge of Statistics, I think with Shodan the Data Scientist would require a deep familiarity with Computer Science and Networking. This is not too hard to come by, but it may not be the repertoire of Data Scientists in Marketing Industry!</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://aliarsalankazmi.github.io/posts/r/2017/11/21/shodan-r-market-security-research.html"> R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/7atjLfahGC0" height="1"></a></div>