library(shodan) library(ggplot2) library(xtable) library(maps) library(rworldmap) library(ggthemes) # if you're behind a proxy, setting this will help # but it's strongly suggested/encouraged that you stick the values in a file and # read them in vs paste them in a script # options(RCurlOptions = list(proxy="host:port", proxyuserpwd="user:pass")) setSHODANKey("~/.shodankey") # query example taken from Michael “theprez98” Schearer's DEFCON 18 presentation # https://www.defcon.org/images/defcon-18/dc-18-presentations/Schearer/DEFCON-18-Schearer-SHODAN.pdf # find all Cisco IOS devies that may have an unauthenticated admin login # setting trace to be TRUE to see the progress of the query result = SHODANQuery(query="cisco last-modified www-authenticate",trace=TRUE) #find the first 100 found memcached instances #result = SHODANQuery(query='port:11211',limit=100,trace=TRUE) df = result$matches # aggregate result by operating system # you can use this one if you want to filter out NA's completely #df.summary.by.os = ddply(df, .(os), summarise, N=sum(as.numeric(factor(os)))) #this one provides count of NA's (i.e. unidentified systems) df.summary.by.os = ddply(df, .(os), summarise, N=length(os)) # sort & see the results in a text table df.summary.by.os = transform(df.summary.by.os, os = reorder(os, -N)) df.summary.by.os # plot a bar chart of them (ggplot(df.summary.by.os,aes(x=os,y=N,fill=os)) + geom_bar(stat="identity") + theme_few() + labs(y="Count",title="SHODAN Search Results by OS")) # generate a PDF world map of locations of the devices (PDFs are nice & scaleable) # using the ggplot2 polygon & point method world = map_data("world") (ggplot() + geom_polygon(data=world, aes(x=long, y=lat, group=group)) + geom_point(data=df, aes(x=longitude, y=latitude), colour="#EE760033",size=1.75) + labs(x="",y="") + theme_few()) # sort & view the results by country # see above if you don't want to filter out NA's df.summary.by.country_code = ddply(df, .(country_code, country_name), summarise, N=sum(!is.na(country_code))) df.summary.by.country_code = transform(df.summary.by.country_code, country_code = reorder(country_code, -N)) df.summary.by.country_code (ggplot(df.summary.by.country_code,aes(x=country_code,y=N)) + geom_bar(stat="identity") + theme_few() + labs(y="Count",x="Country",title="SHODAN Search Results by Country")) # except make a choropleth # using the very simple rworldmap process shodanChoropleth = joinCountryData2Map( df.summary.by.country_code, joinCode = "ISO2", nameJoinColumn = "country_code") par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i") mapCountryData(shodanChoropleth, nameColumnToPlot="N",colourPalette="terrain",catMethod="fixedWidth" )