Metasploit Web Service

Metasploit数据库初始化

  • 参考: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.jssrc/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'
  • 修改文件src/utils/request.js
// 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认证成功。
posted @ 2020-05-03 10:01  三米前有蕉皮  阅读(1380)  评论(0编辑  收藏  举报