由於要進行滲透測試,所以這兩天就在搭LAMP的環境(過程及其痛苦)
這里分享一些我遇到的問題。
首先介紹一下我的使用環境 VM虛擬機,ubuntu 與主機NAT連接
由於之前一直使用的是kali(默認root權限),而ubuntu 默認並不是root權限,所以使用命令行時 請在命令行前加上 sudo
安裝Apache2
首先,我們需要安裝Apache 2 Web服務器。
sudo apt-get install apache2 -y
之后驗證apaqch2是否安裝成功
ifconfig
查看主機ip
打開瀏覽器 輸入上圖中紅線所標的IP地址
如果出現it work 說明安裝成功
安裝MySQL
運行以下命令安裝MySQL。
sudo apt-get install mysql-server -y
然后我發現安裝過程沒有讓我設置mysql的root賬戶密碼
當我使用sudo mysql -u root -p的時候要我輸入密碼
真是一臉懵逼 空密碼 123456 全試了一遍沒用(PS:后來才知道用戶是root 密碼也是root,或者sudo mysql)
解決辦法:利用Ubuntu系統用戶登錄mysql,並修改root密碼。
打開一個文件
sudo vim /etc/mysql/debian.cnf
然后利用這個用戶和密碼登錄mysql
sudo mysql -u debian-sys-maint -p
輸入密碼
成功進入mysql
輸入 update mysql.user set authentication_string=password('password') where user='root'and Host = 'localhost';
( 括號中的passwoed就是你要設置的密碼 不要丟了;號)
如果顯示:
Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
說明修改成功
運行 sudo service mysql restart 重啟mysql服務
運行此命令以保護MySQL。
sudo mysql_secure_installation
這個腳本會問你幾個問題。
第一個問題將要求您安裝驗證密碼插件。
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: N
我通常會回答“N”這個問題,因為我知道我的密碼是安全的。 如果您願意,可以回答“Y”。
接下來,該腳本將要求您為根MySQL用戶設置新密碼。
New password:
Re-enter new password:
該腳本現在將要求您刪除匿名用戶。 回答“Y.”
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
接下來,它會詢問您是否要遠程禁止root登錄。 我們應該總是回答“Y”。
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
它會要求您刪除測試數據庫並訪問它。 回答“Y.”
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
接下來,它會要求您重新加載權限表。 回答“Y.”
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
最后,腳本完成。
安裝phpmyadmin(數據庫圖形管理界面)
sudo apt-get install phpmyadmin
安裝過程中選擇apache2。
接着,安裝完成后,去服務器目錄下檢查,發現並沒有phpmyadmin,這樣的文件或者文件夾
這是因為系統在安裝軟件時,默認將軟件安裝在了/usr/share/下,所以你的phpmyadmin在/usr/share下可以找到
所以,咱們必須建立一個軟連接,使得第三步中顯示的文件和/var/www/html下的某個文檔鏈接起來,回到/var/www/html,輸入一下代碼
sudo ln -s /usr/share/phpmyadmin phpmyadmin
執行效果如圖所示
之后打開瀏覽器輸入
主機IP/phpmyadmin
用戶名 root
密碼 之前設置的
發現我登錄不上phpmyadmin
(要死了)
造成問題的原因:
在運行MySQL 5.7(及更高版本)的Ubuntu系統中,根 MySQL用戶auth_socket默認使用插件進行身份驗證,而不是使用密碼進行身
份驗證。這在許多情況下允許更高的安全性和可用性,但是當您需要允許外部程序(例如phpMyAdmin)訪問用戶時,這也會使事情變
得復雜。
解決方法:
為了使用密碼以root用戶身份連接到MySQL ,您需要將其身份驗證方法從中切換auth_socket為mysql_native_password
步驟:
sudo mysql -u root -p
使用以下命令檢查每個MySQL用戶帳戶使用的身份驗證方法:
mysql> select user,authentication_string,plugin,host from mysql.user;
你可以看到root用戶確實使用auth_socket插件進行了身份驗證。要配置root帳戶以使用密碼進行身份驗證,請運行以下ALTER USER命令。請務必更改password為您選擇的強密碼:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
如果你修改密碼是出現報錯:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
你需要修改密碼驗證的規則等級:
mysql> show variables like 'validate_password%';
修改密碼驗證等級:
mysql> set GLOBAL validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)
修改root的密碼:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ilovexinji.com';
Query OK, 0 rows affected (0.00 sec)
然后你查看root賬號的身份驗證方法:
mysql> select user,authentication_string,plugin,host from mysql.user;
你已經修改密碼成功了,重啟mysql
退出mysql終端
mysql>\q
重啟mysql
sudo service mysql restart
然后你就可以使用root賬號登錄PHPMyadmin了。
安裝PHP
在Ubuntu 18.04上安裝LAMP的最后一步是安裝PHP超文本預處理器。
PHP添加了支持動態網頁的服務器端網頁處理。
運行以下命令以安裝PHP。
apt install php -y
接下來,我們需要告訴Apache首先提供PHP頁面。
打開/etc/apache2/mods-enabled/dir.conf文件並將添加index.php。
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
最后,我們需要重新啟動Apache Web服務器。
sudo service apache2 restart
我們應該確保PHP工作正常。
在/var/www/html中創建一個名為info.php的新文件。
cd /var/www/html
sudo vi info.php
使用以下內容調用info.php:
<?php
phpinfo();
?>
保存並退出該文件。
現在瀏覽到以下URL:
http://主機ip/info.php
您應該看到PHP信息頁面。
這樣說明php也配置成功了
驗證PHP正常工作后刪除該文件。
sudo rm /var/www/html/info.php
附上LAMP的使用手冊
https://oneinstack.com/docs/lampstack-image-guide/