麥郎 發表於 2021-5-6 11:27:00

Centos安装msf与配置

<p>首先查看linux版本信息,</p>
<pre><code>cat /proc/version
cat /etc/issue
cat /etc/redhat-release
uname -a
</code></pre>
<p>对于不同的centos版本可能略有不同, 本实例是采用centos7测试可行<br>
通过msf的安装脚本,</p>
<pre><code>curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb &gt; msfinstall &amp;&amp; \
chmod 755 msfinstall &amp;&amp; \
./msfinstall
</code></pre>
<p>可以方便的安装msf测试版本,之后我们需要对centos下的数据库进行配置。<br>
查看Postgresql 当前版本</p>
<pre><code>psql -V
</code></pre>
<p>没装的话需要使用安装postgresql<br>
尝试自带的postgresql出现问题,导入官方源安装新版本</p>
<pre><code>sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
</code></pre>
<p>这样会安装源文件到<code>/etc/yum.repos.d</code>,不需要的话可以自行清理</p>
<pre><code>rpm -qa | grep Name
rpm -e Name
</code></pre>
<pre><code>sudo yum install -y postgresql10-server postgresql10
sudo /usr/pgsql-10/bin/postgresql-10-setup initdb
sudo systemctl enable postgresql-10.service
sudo systemctl start postgresql-10.service      #开启服务之前一定要初始化
</code></pre>
<pre><code>sudo yum install -y postgresql-server postgresql
postgresql-setup initdb
sudo systemctl start postgresql
sudo systemctl enable postgresql
</code></pre>
<p>不论什么postgresql版本,只要安装好一个版本就可以<br>
对数据库进行设置</p>
<pre><code>su                           #切换到root用户
su postgres                  #切换到数据库用户
createuser msf -P -S -R -D   #创建用户 会提示输入密码
createdb -O msf msf            #创建数据库
createdb -O msf msftest
</code></pre>
<p>这个sql的程序名为psql,默认用户为postgres,通过<code>su</code>和<code>su postgres</code>进入数据库后台管理,获取管理员权限可以通过<code>psql -U postgres</code>获取su,更改密码可以使用<code>ALTER USER postgres WITH PASSWORD 'xxxxxx';</code>或者<code>password postgres</code><br>
删除数据库<code>drop database msf;</code>,删除用户<code>drop role msf;</code>查看数据库列表<code>\l</code>,查看用户列表<code>\du</code>,切换数据库<code>\c DatabaseName</code>查看表<code>\d</code><br>
新建数据库配置文件database.yml,一般我们将它放在.msf/database.yml</p>
<pre><code>production:
   adapter: postgresql
   database: msf
   username: msf
   password: msf               #上一步创建用户的时候设置的密码
   host: 127.0.0.1
   port: 5432
   pool: 75
   timeout: 5
</code></pre>
<p>由于centos默认无法localhost登录,可以使用<code>psql msf -U msf -d msf -h localhost -W</code>登录测试,可能由于防火墙等配置无法访问<code>iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT</code></p>
<pre><code>find / | grep "pg_hba.conf"
vim /var/lib/pgsql/data/pg_hba.conf
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128               md5
</code></pre>
<p>卸载msf</p>
<pre><code>yum remove metasploit-framework

</code></pre>
<pre><code>cd /opt
sudo git clone https://github.com/rapid7/metasploit-framework.git
sudo chown -R `whoami` /opt/metasploit-framework
cd metasploit-framework
yum install postgresql-devel libpcap-devel
cd metasploit-framework

# If using RVM set the default gem set that is create when you navigate in to the folder
rvm --default use ruby-${RUBYVERSION}@metasploit-framework

gem install bundler
bundle install

cd metasploit-framework
sudo bash -c 'for MSF in $(ls msf*); do ln -s /opt/metasploit-framework/$MSF /usr/local/bin/$MSF;done'
sudo nano /opt/metasploit-framework/config/database.yml

production:
   adapter: postgresql
   database: msf_dev_db
   username: msfdev
   password: (your password as same as config file)
   host: 127.0.0.1
   port: 5432
   pool: 75
   timeout: 5

sudo sh -c "echo export MSF_DATABASE_CONFIG=/opt/metasploit-framework/config/database.yml &gt;&gt; /etc/profile"

source /etc/profile
</code></pre>
<p>参考文献:<br>
postgresql数据库基本用法<br>
PostgreSQL新手入门<br>
Deepin Linux下的Metasploit安装及优化<br>
Centos下安装msf</p><br><br>
来源:https://www.cnblogs.com/t0m1tu/p/14734420.html
頁: [1]
查看完整版本: Centos安装msf与配置