PaulSec / API-malwr.com

(Unofficial) Python API for https://malwr.com/
62 stars 34 forks source link

Ugly exit when content unexpected #9

Open nstr10 opened 7 years ago

nstr10 commented 7 years ago

Been using this for awhile and appreciate you work! One small gripe I have is that, because Malwr.com is often not in a usable state, I get a lot of errors from your library.

data = {
  'math_captcha_field': eval(re.findall(pattern, req.content)[0]),
  'math_captcha_question': soup.find('input', {'name': 'math_captcha_question'})['value'],
  'csrfmiddlewaretoken': soup.find('input', {'name': 'csrfmiddlewaretoken'})['value'],
  'share': 'on' if share else 'off',  # share by default
  'analyze': 'on' if analyze else 'off',  # analyze by default
  'private': 'on' if private else 'off'  # private by default
}

IndexError: list index out of range is the most common error, because we're using regular expressions to find content in the response to a request we haven't checked the status of - and we're assuming the result will have an index! I was going to submit a pull request, but realized there are several potential ways to fix this:

Let me know what you think - I'm happy to write the solution, but wouldn't want to waste my time in case you think of a better fix than any of those I've listed.

P.S. I think also the requests library has a property method so you could just check if req.ok is true or false rather than mucking about with status codes.

PaulSec commented 7 years ago

Hey there,

Thanks a lot for your input. You're right, I just had so much trouble lately with Malwr.com. I started working again on this and I will push (maybe tonight) some changes I had on a local branch. Let me know what you think about it and we can work on this if you want.

Thanks a lot though for your feedback, I really appreciated it!

PaulSec commented 7 years ago

Hey, got some trouble with malwr.com getting under maintenance.. but I didn't forget you. I will push it as soon as malwr.com is back up.

nstr10 commented 7 years ago

I've also been waiting for the site to come back. Thinking again about trying to build a Cuckoo sandbox...

PaulSec commented 7 years ago

Yeah, that might be the alternative I will go for too..