- 參考:12098
- 普通用戶初始化數據庫的時候會報下面的錯誤
➜ metasploit-framework git:(Search_Command_Unicode_Support) ./msfdb init
Creating database at /home/kali-team/.msf4/db
Starting database at /home/kali-team/.msf4/db...failed
2020-04-19 20:08:15.754 CST [35133] LOG: database system is shut down
[!] Your database may be corrupt. Try reinitializing.
Creating database users
Writing client authentication configuration file /home/kali-team/.msf4/db/pg_hba.conf
Database is no longer running at /home/kali-team/.msf4/db
Starting database at /home/kali-team/.msf4/db...failed
2020-04-19 20:08:17.959 CST [35287] LOG: database system is shut down
[!] Your database may be corrupt. Try reinitializing.
Creating initial database schema
MSF web service is already running as PID 34484
- 原因是數據庫默認使用
/var/run/postgres
作為套接字的目錄,普通用戶沒有權限訪問。
- 解決方案:取消
/usr/share/postgresql/postgresql.conf.sample
文件里面的unix_socket_directories = '/tmp' # comma-separated list of directories
注釋,然后重啟數據庫服務。
➜ metasploit-framework git:(Search_Command_Unicode_Support) ./msfdb reinit
[?] Would you like to delete your existing data and configurations?: yes
Database is no longer running at /home/kali-team/.msf4/db
Deleting all data at /home/kali-team/.msf4/db
Creating database at /home/kali-team/.msf4/db
Starting database at /home/kali-team/.msf4/db...success
Creating database users
Writing client authentication configuration file /home/kali-team/.msf4/db/pg_hba.conf
Stopping database at /home/kali-team/.msf4/db
Starting database at /home/kali-team/.msf4/db...success
Creating initial database schema
Stopping MSF web service PID 34484
[?] Initial MSF web service account username? [kali-team]:
[?] 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
- 上面還有你設置的web服務的密碼,如果你是隨機生成的請把它記錄下來,免得忘記了又要重新設置。
啟動Web服務
- 如果你執行了
msfdb start
命令啟動的服務可以先執行./msfdb --component webservice stop
停止Web服務再執行msfdb --component webservice -a api.kali-team.cn start
指定綁定地址啟動,然后在/etc/hosts
文件添加本地地址綁定到你自己定義的域名,為什么不用默認的localhost呢?因為會出現一些莫名其妙的錯誤,在vue的跨域請求坑了我兩天,用localhost死活代理不了。
- 訪問
https://api.kali-team.cn:5443/api/v1/api-docs
就可以看到API文檔了,認證就輸入你設置的賬號密碼,他會返回一個token,你點擊認證后復制粘貼到那個編輯框就可以了。
前端開發
- 網上沒找到現成的Metasploit Web前端的代碼,只好自己手擼一個了,這里選擇
Vue Element Admin
后台前端框架,國人寫的,牛批。
- 搭建就自己看官方文檔就可以裝上了,有什么問題可以搜索issue,多數都是中文,應該沒多大問題的。
對接api接口
Vue Element Admin
默認使用mock模擬請求,但是我們有現成的api后端,所以我先把mock注釋掉,添加代理支持跨域請求,折騰了兩天發現是主機名不能同時為localhost,差點崩潰了。
- 修改根目錄
vue.config.js
文件的devServer
,這些參數是什么意思請看devserver-proxy
devServer: {
port: port,
https: true,
host: 'web.kali-team.cn',
// open: true,
overlay: {
warnings: false,
errors: true
},
proxy: {
'/api': {
target: `https://api.kali-team.cn:5443/`,
changeOrigin: true,
ws: true,
secure: false
// pathRewrite: {
// ['^' + process.env.VUE_APP_BASE_API]: ''
// }
}
}
// before: require('./mock/mock-server.js')
},
- 修改基礎URL為
/api/v1
,方便以后更新迭代版本時修改。
// create an axios instance
const service = axios.create({
baseURL: '/api/v1', // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout: 5000 // request timeout
})
- 修改
src/api/user.js
文件里面用戶登錄函數的URL路徑,就是按照API文檔里面的寫就可以了。
export function login(data) {
return request({
url: '/auth/generate-token',
method: 'post',
data
})
}
- 執行
npm run dev
啟動前端服務,輸入你的賬號密碼點擊登錄,查看瀏覽器開發者工具的NetWork應該就可以看到有數據返回來就說明API接口可以正常調用了。
登錄認證
- 自帶有用戶名校驗,我們不需要,注釋掉
src/utils/validate.js
和src/views/login/index.vue
的用戶部分。
- 修改請求api接口的URL為
'auth/generate-token
export function login(data) {
return request({
url: '/auth/generate-token',
method: 'post',
data
})
}
- 自帶的事cookie認證,但是Metasploit的API是通過token認證的,所以我們要把
Authorization
加到請求頭,這里有一個坑就是token前面還要添加一個Bearer
,然后再接上token,不然會認證失敗。
- 修改文件
src/utils/auth.js
const TokenKey = 'Authorization'
// request interceptor
service.interceptors.request.use(
config => {
// do something before request is sent
if (store.getters.token) {
// let each request carry token
// ['X-Token'] is a custom headers key
// please modify it according to the actual situation
config.headers['Authorization'] = 'Bearer ' + getToken()
}
return config
},
error => {
// do something with request error
console.log(error) // for debug
return Promise.reject(error)
}
)
- 將token添加到請求頭后再去請求
/user
這個接口獲取用戶信息,如果可以獲取就說明token認證成功。