Metasploit 中连接postgres 数据库

kali linux 2017.1 中 Metasploit 连接 postgres 数据库

  1. 重启 postgres 数据库

     root@attacker:~# systemctl restart postgresql.service 
    
  2. 修改数据库用户账号(postgres)的密码

     1. 以管理员身份登录数据库 postgres 用户
     	root@attacker:~# sudo -u postgres psql
     		psql (9.6.3)
     		Type "help" for help.
     2. 修改数据库 postgres 用户的密码
     		postgres=# alter user postgres with password 'admin';
     		ALTER ROLE
     		postgres=# \q (退出数据库)
    
  3. 修改 Linux 系统的 postgres 用户的密码(密码与数据库用户 postgres 的密码相同)

     1. 修改 postgres 数据库用户的密码
     	root@attacker:~# passwd postgres 
     	Enter new UNIX password: 	admin
     	Retype new UNIX password: 	admin
     	passwd: password updated successfully
    
  4. 修改 PostgresSQL 数据库配置实现远程访问

     1. 修改数据库监听地址
     	root@attacker:~# vim /etc/postgresql/9.6/main/postgresql.conf
     		listen_addresses = '0.0.0.0'	#59行 
     		password_encryption = on	#88行 
     2. pg_hba.conf是客户端认证配置文件,定义如何认证客户端
     	root@attacker:~# vim /etc/postgresql/9.6/main/pg_hba.conf 
     		host 	all		all		0.0.0.0 		md5		#93行
     3. 重启 postgres 数据库服务
     root@attacker:~# systemctl restart postgresql.service 
    
  5. 管理PostgreSQL用户和数据库

     1. 以管理员身份登录数据库 postgres 用户
     	root@attacker:~# psql -U postgres -h 127.0.0.1
     	Password for user postgres:  admin
     	psql (9.6.3)
     	SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
     	Type "help" for help.
     2. 创建数据库用户及其密码
     	postgres=# create user msf with password 'admin';
     	CREATE ROLE
     3. 修改数据库用户密码	
     	postgres=# alter user postgres with password 'admin';
     	ALTER ROLE
     4. 创建数据库及其属主
     	postgres=# create database msf with owner=msf;
     	CREATE DATABASE
     5. 退出数据库	
     	postgres=# \q	(退出数据库)
    
  6. metasploit 配置连接

     1. 切换渗透测试数据库
     	msf > db_status 
     		[*] postgresql connected to msf
     	msf > db_disconnect
     	msf > db_status 
     		[*] postgresql selected, no connection
     2. 连接 postgres 数据库
     	msf > db_status 
     		[*] postgresql selected, no connection
     	msf > db_connect 
     		[*]    Usage: db_connect <user:pass>@<host:port>/<database>
     		[*]       OR: db_connect -y [path/to/database.yml]
     		[*] Examples:
     		[*]        db_connect user@metasploit3
     		[*]        db_connect user:pass@192.168.0.2/metasploit3
     		[*]        db_connect user:pass@192.168.0.2:1500/metasploit3
     	msf > db_connect msf:admin@127.0.0.1/msf (数据库中的用户和密码)
     		[*] Rebuilding the module cache in the background...	
     	msf > db_status 
     		[*] postgresql connected to msf
    
  7. 配置自动连接

     1. 创建文件备份
     	root@attacker:/usr/share/metasploit-framework/config# cp database.yml database.yml.bak
     2. 从样例复制文件
     	root@attacker:/usr/share/metasploit-framework/config# cp database.yml.example database.yml
     3. 编辑文件
     	root@attacker:/usr/share/metasploit-framework/config# vim database.yml
     	development: &pgsql
     	  adapter: postgresql
     	  database: msf		#数据库名
     	  username: msf		#数据库用户名
     	  password: admin	#数据库用户密码
     	  host: localhost
     	  port: 5432
     	  pool: 200
     	  timeout: 5
    
  8. 重新连接 msfconsole

     root@attacker:~# msfconsole 
    
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值