3
  5   ˆl–Ým_JJeJe@µq±\ ”Å£�þDÛ«7(¤�Â yà?Ì599ËÂÈ W    #!/usr/bin/python3

# $Id: rst2pseudoxml.py 8927 2022-01-03 23:50:05Z milde $
# Author: David Goodger <goodger@python.org>
# Copyright: This module has been placed in the public domain.

"""
A minimal front end to the Docutils Publisher, producing pseudo-XML.
"""

try:
    import locale
    locale.setlocale(locale.LC_ALL, '')
except:
    pass

from docutils.core import publish_cmdline, default_description


description = ('Generates pseudo-XML from standalone reStructuredText '
               'sources (for testing purposes).  ' + default_description)

publish_cmdline(description=description)
     ˆÇÆË‚pÅÂÈ Z    ‹      Õ–QoÚ0Çßû)<?ì�\	-“Ú�©#HCk)¢LÓ4MÈØ†X$vd_ ìÓÏ! ÒŽjÝÃºñ”óåûÿ;[ÎEo’Ûîøë°G>Žo®Éðó‡ë~—ÐÀ—V 'õ‹³à´	ÐPBSÄâ`µZ«V`ìÆ#H1ÏÎÀ¡U�‚Æ'Q•‹OH”J&ü“D¨0“q_yOÌŒ€)Ñ)!Ã] ÂäœÔb¦2™› u7¦ðÃ]Ã¹l§öË­¹ž2ï.ÚmpåÔ'Qæ°äŽµ 0+i#¨öV`ë%š±®,6ÿ…¿ê¦lºqU…6Ž0%K–©¹îP4�#•Ï‰³¼CAq£L3¦Á\Í(avè·~÷ö»×¦Õ×qÄHjå¬Cßw;ƒËÛNBãËeì°æÆk®h|Í’Ü5SR<+¾«ÅwêÇó&µ&‘Ž[U 2úA
q•›ÌÌ³ž{‚Ôî«j‰ø]5TŒáÕ¨7'ýQ]QMñàî6—ÆCf¥F’(+9»ÞÒ×VÞê©+.wC²e³jž"�	i�ƒÊ?(H©Ú¬ô~M|½Vƒ¹µæ4Þ<öM>qž†íF3lœ†¤Ù¼Ï	yFèo‡O¯i¿DãJWøÍ›™±õ$wžæ@öá¼­Éh¼^Žþ/¶Ô¨r9aÕRNJøí9�<ÂÝyBQÅ¿ Uñ£I]ý—ÄÖ6qÄH–{g°3P}ÏIñä>Î1`éØ|�k3üû8/ìO`Û¹E°i##¨;ÝŸìÂáL    6   ˆl–Ðz¾”ŠeJeAà™¸ËêbÑ¿�þBë$Y¹Dã­ÆGŠñüÿÍƒmöžÌÃÉ <    local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"
local base64 = require "base64"
local string = require "string"
local table = require "table"
local io = require "io"

local libssh2_util = require "libssh2-utility"

description = [[
This script takes a table of paths to private keys, passphrases, and usernames
and checks each pair to see if the target ssh server accepts them for publickey
authentication. If no keys are given or the known-bad option is given, the
script will check if a list of known static public keys are accepted for
authentication.
]]

---
-- @usage
--  nmap -p 22 --script ssh-publickey-acceptance --script-args "ssh.usernames={'root', 'user'}, ssh.privatekeys={'./id_rsa1', './id_rsa2'}"  <target>
--
-- @usage
--  nmap -p 22 --script ssh-publickey-acceptance --script-args 'ssh.usernames={"root", "user"}, publickeys={"./id_rsa1.pub", "./id_rsa2.pub"}'  <target>
--
-- @output
-- 22/tcp open  ssh     syn-ack
-- | ssh-publickey-acceptance:
-- |   Accepted Public Keys:
-- |_    Key ./id_rsa1 accepted for user root
--
-- @args ssh.privatekeys Table containing filenames of privatekeys to test
-- @args ssh.passphrases Table containing passphrases for each private key
-- @args ssh.publickeys Table containing filenames of publickkeys to test
-- @args ssh.usernames Table containing usernames to check
-- @args knownbad   If specified, check if keys from publickeydb are accepted
-- @args publickeydb  Specifies alternative publickeydb

author = "Devin Bjelland"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"auth", "intrusive"}

local privatekeys = stdnse.get_script_args "ssh.privatekeys"
local passphrases = stdnse.get_script_args "ssh.passphrases" or {}
local usernames = stdnse.get_script_args "ssh.usernames"
local knownbad = stdnse.get_script_args "knownbad"
local publickeys = stdnse.get_script_args "ssh.publickeys"
local publickeydb = stdnse.get_script_args "publickeydb" or nmap.fetchfile("nselib/data/publickeydb")
portrule = shortport.ssh

function action (host, port)
  local result = stdnse.output_table()
  local r = {}
  local helper = libssh2_util.SSHConnection:new()
  local failures = 0
  local successes = 0
  if publickeys and usernames then
    for j = 1, #usernames do
      for i = 1, #publickeys do
        stdnse.debug("Checking key: " .. publickeys[i] .. " for user " .. usernames[j])
        local status, result = helper:read_publickey(publickeys[i])
        if not status then
          stdnse.verbose("Error reading key: " .. result)
        elseif helper:connect(host, port) then
          successes = successes + 1
          local status, err = helper:publickey_canauth(usern