前言

初始化数据库

image-20200903153206140.png

开发模板

def report_store_config(config)
    service_data = {
        address: config[:hostname], # 就是服务的IP地址
        port: config[:port], # 服务开放的端口
        service_name: 'smb', # 服务的名称
        protocol: 'tcp', # 服务连接的协议
        workspace_id: myworkspace_id # 这个不用改(默认)
        }

    credential_data = {
        origin_type: :session, # 来源类型,cong目标session得到的就是当前session的实例化对象
        session_id: session_db_id, # session的id
        post_reference_name: refname, # 当前执行的模块名称,就是你用哪一个模块获取的信息
        private_type: :password, # 密码类型,是明文密码还是,hash密文
        private_data: config[:password], # 密码,字符串,一定要UTF-8编码,不然进数据库会报错
        username: config[:username] # 用户名
        }.merge(service_data)

    credential_core = create_credential(credential_data)

    login_data = {
        core: credential_core,
        status: Metasploit::Model::Login::Status::UNTRIED # 密码登录的状态,下面详细说明
        }.merge(service_data)

    create_credential_login(login_data)
end

metasploit凭证ER图

image-20201130105524896.png

service_data

属性 描述
address 获取到的服务IP地址
port 服务对应的端口
service_name 大概就这些:ssh,http,https,ftp,mssql,postgres,smb,jboss…,Nmap扫出什么就写什么
protocol tcp,udp
workspace_id 默认

image-20201130110158304.png

credential_data

属性 描述
origin_type 数据来源的类型::sessiom(是在目标session获取的),:import(从文件导入的),:services(auxiliary模块扫描得到的),:manuals(手工添加的),还有爆破出来等等
session_id 如果origin_type是在session获取就要填,session的id
post_reference_name 通过哪一个post模块得到的,编写后渗透模块选这个
module_fullname 编写auxiliary模块,选这个
filename 密码是通过从文件导入的,选这个
private_type 密码的类型::password(明文密码),:ssh_key(ssh_密钥),:ntlm_hash(NTLM_HASH),:postgres_md5(postgres数据库 MD5),:nonreplayable_hash(不可重放hash),:(空白)
private_data 比较重要的数据,有帐号和密码
public_data 不那么重要的数据,普通用户可以通过API查看,只能看到用户名
realm_key Metasploit::Model::Realm::Key::XXX,realm_type (domain db2db sid pgdb rsync wildcard)
realm_value 对应realm_key的值
username 用户名
jtr_format 如果通过hashcat或者John the ripper这些密码恢复工具得到的就需要填写

image-20201130111105864.png

login_data

属性 描述
status 没有测试过不知道密码的:Metasploit::Model::Login::Status::UNTRIED通过爆破登录成功的:Metasploit::Model::Login::Status::SUCCESSFUL密码不正确的:Metasploit::Model::Login::Status::INCORRECT无法连接的:Metasploit::Model::Login::Status::UNABLE_TO_CONNECT被锁定了的:Metasploit::Model::Login::Status::LOCKED_OUT被禁用了的:Metasploit::Model::Login::Status::DISABLED

使用示例

def report_creds(user_data)
    user = user_data.user_name
    pass = "#{user_data.lanman}:#{user_data.ntlm}"
    return if (user.empty? || pass.include?('aad3b435b51404eeaad3b435b51404ee'))

    # Assemble data about the credential objects we will be creating
    credential_data = {
        origin_type: :session,
        post_reference_name: 'hashdump',
        private_data: pass,
        private_type: :ntlm_hash,
        session_id: client.db_record.id,
        username: user,
        workspace_id: shell.framework.db.workspace.id
        }

    credential_core = shell.framework.db.create_credential(credential_data)

    # Assemble the options hash for creating the Metasploit::Credential::Login object
    login_data = {
        core: credential_core,
        status: Metasploit::Model::Login::Status::UNTRIED,
        address: ::Rex::Socket.getaddress(client.sock.peerhost, true),
        port: 445,
        service_name: 'smb',
        protocol: 'tcp',
        workspace_id: shell.framework.db.workspace.id
        }

    shell.framework.db.create_credential_login(login_data)
end

image-20201130113243014.png

image-20201130113243014

image-20201130113349878.png

image-20200905153833548.png

image-20200905153833548

参考

https://github.com/rapid7/metasploit-framework/pull/14432

https://github.com/rapid7/metasploit-framework/blob/master/documentation/api/v1/credential_api_doc.rb

Powered by Kali-Team