GithubHelp home page GithubHelp logo

JSON Parsing Issue about mihari HOT 12 CLOSED

ninoseki avatar ninoseki commented on July 30, 2024
JSON Parsing Issue

from mihari.

Comments (12)

ninoseki avatar ninoseki commented on July 30, 2024

I cannot reproduce the error.
The following two commands work in my env.

mihari shodan 'ssl:"MetasploitSelfSignedCA" http.favicon.hash:"-127886975"'
mihari shodan 'hash:-1564315793'

from mihari.

ssnkhan avatar ssnkhan commented on July 30, 2024

How odd.

The queries work providing there is not a result which contains something that breaks the parser. When that happens, none of the results (for that query) get pushed into the db. I had the same issue today:

/usr/lib/ruby/2.7.0/json/common.rb:156:in `parse'
/usr/lib/ruby/2.7.0/json/common.rb:156:in `parse'
/var/lib/gems/2.7.0/gems/shodanx-0.2.1/lib/shodan/clients/base.rb:45:in `block in request'
/usr/lib/ruby/2.7.0/net/http.rb:933:in `start'
/usr/lib/ruby/2.7.0/net/http.rb:606:in `start'
/var/lib/gems/2.7.0/gems/shodanx-0.2.1/lib/shodan/clients/base.rb:36:in `request'
/var/lib/gems/2.7.0/gems/shodanx-0.2.1/lib/shodan/clients/base.rb:56:in `get'
/var/lib/gems/2.7.0/gems/shodanx-0.2.1/lib/shodan/clients/host.rb:36:in `search'
/var/lib/gems/2.7.0/gems/mihari-1.5.0/lib/mihari/analyzers/shodan.rb:44:in `search_with_page'
/var/lib/gems/2.7.0/gems/mihari-1.5.0/lib/mihari/analyzers/shodan.rb:54:in `block in search'

This is the IP causing the issue today: https://beta.shodan.io/host/180.215.106.226

Is there an equivalent of on error resume next or something similar? So if the Metasploit query say has 100 results, if one triggers an error, none of the remaining 99 are added to the DB.

Really appreciate your help.

from mihari.

ninoseki avatar ninoseki commented on July 30, 2024

I cannot fix the issue which cannot reproduce

from mihari.

ssnkhan avatar ssnkhan commented on July 30, 2024

I have done a fresh install of Ruby 3.0 on a fresh Ubuntu machine, and seem to keep running into this issue. I tried updating cli.rb with :quirks_mode => true (i.e. json.parse (input, :quirks_mode => true) but that falls over completely. According to Google, the error is caused by invalid JSON, in this instance being returned by the Shodan API.

Is there anything I can provide with regard to debugging that might help identify the root cause? I am wondering whether this issue happens if there are many results (some searches return 50+ results).

Thanks again for all your help!

from mihari.

ssnkhan avatar ssnkhan commented on July 30, 2024

Just had another look into the log file that I have been using to capture the errors. Looks like the same parse error is generated when the API returns a api.shodan.io | 502: Bad gateway error. What follows is the Cloudflare interstitial (HTML).

I wonder whether the size of the response could also be at play here; the other JSON errors appear in the log file and abruptly cut off part way through the http.favicon_hash key/value, which does contain numerous characters.

from mihari.

ninoseki avatar ninoseki commented on July 30, 2024

@ssnkhan my understandings are:

  • Shodan API returns an invalid JSON
  • Mihari fails to parse a response from the API (because its format is invalid)

Are they right?
If so I think it's good to claim the issue to Shodan. 🤔

from mihari.

ninoseki avatar ninoseki commented on July 30, 2024

Also, please provide the actual command you ran.
It will make me easier to find a clue from your complaints.

from mihari.

ssnkhan avatar ssnkhan commented on July 30, 2024

Thanks @ninoseki. The query is:

mihari shodan 'ssl:"MetasploitSelfSignedCA" http.favicon.hash:-127886975 -http.title:"Bam! Application Error"' --title "Metasploit C2" --tags "C2"

This query, and maybe 20 others, are ran via a cronjob. Looking at the result on Shodan (for the specific error in my log file) for the host https://beta.shodan.io/host/180.215.106.226/raw, the JSON is complete, but you will note that the response is very lengthy.

Having done some more Googling, I suspect the issue may also be related to throttling by Shodan. Let me add some sleep 5 into my script and see if the issue persists.

from mihari.

ssnkhan avatar ssnkhan commented on July 30, 2024

Update: sprinkling sleep 5 has had no effect, and the same query continues to generate the above errors (not always, but reasonably consistently).

from mihari.

ninoseki avatar ninoseki commented on July 30, 2024

Could you report the issue to Shodan, please?
The issue is caused by the error on the Shoda API side.
There is nothing I can do it with.

from mihari.

ssnkhan avatar ssnkhan commented on July 30, 2024

Thanks @ninoseki — I’ll raise the issue with Shodan.

However, could error handling be improved so that invalid JSON doesn’t interrupt the importing of other valid IOCs as part of the same query?

from mihari.

ninoseki avatar ninoseki commented on July 30, 2024

However, could error handling be improved so that invalid JSON doesn’t interrupt the importing of other valid IOCs as part of the same query?

Okey, it makese sense to me.
I will work on that.

from mihari.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.