1、安装PostgreSQL
通过homebrew来安装,命令很简单
brew install postgresql
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
安装完成后,在终端运行如下命令
/usr/local/opt/postgres/bin/createuser -s postgres
就可以使用`psql -U postgres` 登陆了
(如果不允许这条命令的话psql: FATAL: role "postgres" does not exist,重启后就等不上去了)
psql (11.3)
Type "help" for help.
postgres=#
2、启动 重启 停止PostgreSQL 服务,【如果上面出现postgres=#,可跳过2、3这段,直接到4】
启动:
brew services start postgresql
重启:
brew services restart postgresql
停止:
brew services stop postgresql
3、登录PostgreSQL 数据库
开启PostgreSQL 服务后,在终端输入:
psql -U postgre -h ip地址 "password=密码"
可以使用如下命令,为postgre 用户更改密码
alter user postgres with password 'XXXXXX';
4、用户操作
对应命令如下(在postgres=# 环境下):
1.查看数据库用户列表: \du
2.创建数据库用户: create user msf with password 'msf';
3.删除数据库用户: drop user msf;
5、数据库操作【可忽略】
对应命令如下(在postgres=# 环境下):
1.查看数据库列表: \l (list的意思)
2.创建数据库: create database db1;
3.删除数据库: drop database db1;
6、数据表操作【可忽略】
1.选择数据库: \c DatabaseName (choose的意思)
2.创建数据库表: create table people;
3.删除数据库表: drop table people;
4.查看数据库信息:\d (database list的意思)
具体参见PostgreSQL 中文手册
msf初始化数据库:msfdb init
如果出错使用:msfdb reinit
root-Air:~ root$ msfdb reinit
[?] Would you like to delete your existing data and configurations?:
Please answer yes or no.
[?] Would you like to delete your existing data and configurations?: yes
Stopping database at /Users/root/.msf4/db
Deleting all data at /Users/root/.msf4/db
Creating database at /Users/root/.msf4/db
Starting database at /Users/root/.msf4/db...success
Creating database users
Writing client authentication configuration file /Users/root/.msf4/db/pg_hba.conf
Stopping database at /Users/root/.msf4/db
Starting database at /Users/root/.msf4/db...success
Creating initial database schema
Stopping MSF web service PID 64966
[?] Initial MSF web service account username? [root]: msf
[?] Initial MSF web service account password? (Leave blank for random password):
Generating SSL key and certificate for MSF web service
Attempting to start MSF web service...success
MSF web service started and online
Creating MSF web service user msf
############################################################
## MSF Web Service Credentials ##
## ##
## Please store these credentials securely. ##
## You will need them to connect to the webservice. ##
############################################################
MSF web service username: msf
MSF web service password: msf
MSF web service user API token: c8e...0a32dbc6cbc810...6
MSF web service configuration complete
The web service has been configured as your default data service in msfconsole with the name "local-https-data-service"
If needed, manually reconnect to the data service in msfconsole using the command:
db_connect --token c8e...0a32dbc6cbc810...6 --cert /Users/root/.msf4/msf-ws-cert.pem --skip-verify https://localhost:5443
The username and password are credentials for the API account:
https://localhost:5443/api/v1/auth/account
出现下面提示可以使用msfupdate升级msf:
This copy of metasploit-framework is more than two weeks old.
Consider running 'msfupdate' to update to the latest version.
如果升级中断可能出现下面错误:
root$ msfupdate
Switching to root user to update the package
Downloading package...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Checking signature...
Could not open package: metasploitframework-latest.pkg
Cleaning up...
metasploitframework-latest.pkg
root-Air:framework root$ ./msfupdate
[*]
[*] Attempting to update the Metasploit Framework...
[*]
[-] ERROR: User running msfupdate does not own the Metasploit installation
[-] Please run msfupdate as the same user who installed Metasploit.
直接手动下载安装
http://osx.metasploit.com/metasploitframework-latest.pkg
添加到系统变量:
https://blog.csdn.net/handsomefuhs/article/details/79687381
export MONO_HOME=/Library/Frameworks/Mono.framework/Versions/5.0.1
export PATH=$PATH:$MONO_HOME/bin
export PATH=$PATH:/opt/metasploit-framework/bin
其他记录:
默认metasploit监听5433端口,找到postgresql.conf,修改如下
# Add settings for extensions here
port = 5432
修改postgresql用户密码
https://blog.csdn.net/xocoder/article/details/24479751
sudo su postgres
psql postgres
alter user postgres with password 'new password'
2.进入postgresql中,设置默认用户密码、创建新用户、设置新用户权限、创建数据库:
sudo -u postgres psql#进入postgresql默认的用户
alter user postgres with password '密码'; #设置默认用户的登录密码
create user '用户名' wiht password '密码' nocreatedb; #创建带密码的新用户
create database '数据库名' with owner = '用户名'; #创建数据库并指定数据库的所属用户
\q
3.进入metasploit,连接数据库:
msfconsole
db_status#查看数据库的状态
db_connect 用户名:密码@主机地址\数据库名
db_status#检查是否开启成功
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------------------------------------------------------------------
安装参考:https://blog.csdn.net/u012566895/article/details/50523476
下载pkg文件安装参考:https://blog.csdn.net/myfather103/article/details/79212460
数据库其他参考:
https://blog.csdn.net/myfather103/article/details/69883089
https://blog.csdn.net/xysoul/article/details/47123029
https://blog.csdn.net/ericzhangyuncsdn/article/details/79455882