A-A+

Metasploit 安装 Postgres设置

2019年04月16日 23:42 汪洋大海 暂无评论 共4100字 (阅读2,572 views次)

注意:您不再需要手动为MSF设置Postgres数据库,请参阅有关如何使用捆绑的嵌入式Postgresql数据库安装Metasploit Penetration Testing Framework的更新指南。

此页面调整了Metasploit Wiki:Postgres设置到Fedora的说明。

🔗 允许密码验证访问localhost上的postgres

允许帐户msf_user使用基于密码的身份验证连接到数据库msf_user。编辑“/var/lib/pgsql/data/pg_hba.conf”,更改:

host     all            all            127.0.0.1/32          ident

host    "msf_database"	"msf_user"      127.0.0.1/32          md5
host     all             all            127.0.0.1/32          ident

另请参阅:Postgresql Wiki:客户端身份验证Postgresql文档:pg_hba.conf

🔗 开始postgres

user@magnolia:$ sudo -s
user@magnolia:$ postgresql-setup initdb
user@magnolia:$ systemctl start postgresql.service

🔗 成为postgres用户

root@magnolia:# su postgres

🔗 创建数据库用户

postgres@magnolia:$ createuser msf_user -P
Enter password for new role: yourmsfpassword
Enter it again: yourmsfpassword 
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n

🔗 创建数据库

postgres@magnolia:$ createdb --owner=msf_user msf_database

🔗 配置Metasploit

通过运行msfconsole启动框架,然后输入以下命令:

msf > db_status 
[*] postgresql selected, no connection
msf> db_connect msf_user:[email protected]:5432/msf_database
NOTICE:  CREATE TABLE will create implicit sequence "hosts_id_seq" for serial column "hosts.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "hosts_pkey" for table "hosts"
[..]
NOTICE:  CREATE TABLE will create implicit sequence "mod_refs_id_seq" for serial column "mod_refs.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "mod_refs_pkey" for table "mod_refs"

🔗 启动时启用数据库

将数据库配置写入单独的配置文件,这样在每次启动msfconsole时都不会在屏幕上打印密码。请不要在属性前面添加空格字符而不是制表符。

$ cat > /opt/metasploit4/config/database.yml << EOF
production:
    adapter: postgresql
    database: msf_database
    username: msf_user
    password: yourmsfpassword
    host: 127.0.0.1
    port: 5432
    pool: 75
    timeout: 5
EOF

使用数据库配置文件并在每次启动msfconsole时连接到此数据库。也改为你当前的测试项目的工作区。
注意注意:::在~/.msf4/ 建立database.yml 内容是上面的就可以!!!

$ cat > ~/.msf4/msfconsole.rc << EOF
db_connect -y /opt/metasploit4/config/database.yml
workspace -a YourProject
EOF

🔗 使用数据库

配置和连接数据库后,您可以使用它来存储信息。首先检查数据库状态:

msf > db_status
[*] postgresql connected to msf_database

扫描本地网络网络:

msf > db_nmap 192.168.1.0/24

列出数据库中的主机:

msf > hosts

Hosts
=====

address        mac                name       os_name  os_flavor  os_sp  purpose  info  comments
-------        ---                ----       -------  ---------  -----  -------  ----  --------
192.168.1.1    11:22:33:44:55:66  router     Linux    2.6.X             device         
192.168.1.100  22:33:44:55:66:77  mixer      Linux    2.6.X             device  

列出已安装的metasploit版本的所有db命令:

msf > help database

Database Backend Commands
=========================

    Command        Description
    -------        -----------
    creds          List all credentials in the database
    db_connect     Connect to an existing database
    db_disconnect  Disconnect from the current database instance
    db_export      Export a file containing the contents of the database
    db_import      Import a scan result file (filetype will be auto-detected)
    db_nmap        Executes nmap and records the output automatically
    db_status      Show the current database status
    hosts          List all hosts in the database
    loot           List all loot in the database
    notes          List all notes in the database
    services       List all services in the database
    vulns          List all vulnerabilities in the database
    workspace      Switch between database workspaces

🔗 故障排除

如果遇到问题或需要修改用户或数据库,则始终可以使用psql命令执行此操作。如果你正在使用IDENT身份验证(在Fedora和RHEL上默认),你必须成为'postgres'用户才能用psql修改用户或数据库。(请参阅上面的成为postgres用户

🔗 列出数据库

postgres@magnolia:$ psql -l

🔗 分配数据库的所有权

要更改数据库的所有者,请将以下命令传递给psql:“ALTER DATABASE name OWNER TO new_owner”例如:

postgres@magnolia:$ psql -c "ALTER DATABASE msf_database OWNER TO msf_user;" 

🔗 添加或更改用户的密码

要更改postgres用户的密码,请将以下命令传递给psql:“ALTER USER username WITH ENCRYPTED PASSWORD'passwd';” 例如:

postgres@magnolia:$ psql -c "ALTER USER msf_user WITH ENCRYPTED PASSWORD 'omgwtfbbq';" 

🔗 删除数据库

Postgres提供了一个方便的'dropdb'命令。

postgres@magnolia:$ dropdb msf_database

🔗 删除用户

Postgres提供了一个方便的'dropuser'命令。

postgres@magnolia:$ dropuser msf_user

🔗 其他有用的postgres提示

如果您需要修改postgres系统中的任何内容,psql是一个方便的工具。如果您更喜欢图形工具,pgadmin3非常好。有关更多信息,请参阅此处的(大量)文档:http//www.postgresql.org/docs/manuals/

文章来源:https://fedoraproject.org/wiki/Metasploit_Postgres_Setup

解决办法

  对于命令解释
  msfdb init    # initialize the database
  msfdb reinit    # delete and reinitialize the database
  msfdb delete   # delete database and stop using it
  msfdb start    # start the database
  msfdb stop    # stop the database

如果不想每次开机都这样,还可以配置随系统启动。

update-rc.d postgresql enable

update-rc.d metasploit enable

布施恩德可便相知重

微信扫一扫打赏

支付宝扫一扫打赏

×

给我留言