2019-01-28
Python Import the class within the same directory or sub directory
markdown
# 引用同一資料夾中的類別
假設有已有如下的資料結構,在 myfolder 中有 Order, Product, User, Manager 四個 class,要引用到 main.py 中使用。
```
myfolder
+-- main.py
+-- subdir
| +-- order.py
| +-- product.py
+-- user.py
+-- manager.py
```
## Python 2
建立一個名為 `__init__.py` 的空檔案,放在同一個資料夾中
在 main.py 中
```
from user import User
from manager import Manager
```
資料夾範例:
```
myfolder
+-- main.py
+-- subdir
| +-- order.py
| +-- product.py
+-- __init__.py
+-- user.py
+-- manager.py
```
如果是要引用子目錄中的類別,則是在子目錄中建立 `__init__.py`
```
from subdir.order import Order
from subdir.product import Product
```
子資料夾範例:
```
myfolder
+-- main.py
+-- subdir
| +-- __init__.py
| +-- order.py
| +-- product.py
+-- user.py
+-- manager.py
```
## Python 3
在同一目錄下引用直接使用 .user,參考如下:
在 main.py 中
```
from .user import User
from .manager import Manager
```
資料夾範例:
```
myfolder
+-- main.py
+-- subdir
| +-- order.py
| +-- product.py
+-- __init__.py
+-- user.py
+-- manager.py
```
2019-01-21
Kali Linux 新增使用者帳號並授與 sudo 權限
markdown
在網路上查閱很多 Kali 的相關文章,大多都是直接使用 root 帳號,在使用 Linux 時通常會建議不要直接使用 root 帳號進行一般事務的管理操作。所以查了如何在 kali 加入新的使用者帳號,操作指令可以參考 Degain 或是 Ubuntu 的文章。
以下 username 都要代換為要新增的帳號
# 新增帳號
1. 開啟 Terminal ,使用 Ctrl+Alt+T,或是點擊左側的 Terminal 圖示,並登入 root 帳號
2. 加入新使用者帳號:
```
useradd -m username
```
-m 建立帳號的 home 目錄,預設路徑是 /home/username
3. 建立帳號的密碼:
```
passwd username
```
4. 將帳號加到 sudo 群組,帳號才能使用 sudo 命令安裝程式:
```
usermod -a -G sudo username
```
-a 加入
-G 指定要加入的群組名稱
5. 給帳號指定預設的 shell:
```
chsh -s /bin/bash username
```
-s 指定登入的 shell
# 移除帳號
1. 將帳號從 sudo 群組移除:
方法1. 使用 deluser:
```
sudo deluser username sudo
```
方法2. 使用 gpasswd:
```
sudo gpasswd -d username sudo
```
2. 將帳號從系統移除:
```
sudo userdel -r username
```
-r 移除帳號的 home 目錄和郵件
# 參考:
* [Adding a new user in Kali Linux](https://www.linkedin.com/pulse/20140502074357-79939846-adding-a-new-user-in-kali-linux)
在 Kali Linux 安裝 Visual Studio Code
markdown
# Kali 安裝 Visual Studio Code
因為 Kali 是以 Debian 為基地的發佈版,所以參考 Debian 或是 Ubuntu 的安裝方式。
```
::decode
# Download the Microsoft GPG key, and convert it from OpenPGP ASCII
# armor format to GnuPG format
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
# Move the file into your apt trusted keys directory (requires root)
mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
# Add the VS Code Repository
echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list
# Update and install Visual Studio Code
apt update && apt install code
```
# 參考
1. [Visual Studio Code on Linux](https://code.visualstudio.com/docs/setup/linux)
2019-01-18
kali 建立應用程式捷徑 (Desktop Entry)
markdown
kali linux 是使用 Gnome 桌面環境,如果要自訂應用程式捷徑和分類可以參考 [Desktop Entry Specification](https://developer.gnome.org/desktop-entry-spec/)。
這裡的情境是從網路下載了 burp suite 要直接建立捷徑執行。假設已將程式下載解壓,並儲存在 /opt/burpsuite 資料夾。
```
root@kali:/opt/burpsuite# ls -l
-rw------- 1 root root 7340 Jan 17 22:20 burpsuite.png
-rwxrw-rw- 1 root root 28215285 Aug 12 19:55 burpsuite_v1.7.37.jar
```
# 資料夾
```
/etc/xdg/menus # 主選單設定
/etc/xdg/menus/applications-merged/kali-applications.menu # kali 預設選單層級和 Category 名稱設定
/usr/share/applications # 將 DesktopEntry 檔案放在這資料夾內(副檔名 .desktop)
/usr/share/desktop-directories # 應用程式分類資料夾設定(副檔名 .directory)
```
# 執行 burp suite
用 java 執行 burpsuite 確認一下能正常啟動應用程式
```
root@kali:/opt/burpsuite# java -jar burpsuite_v1.7.37.jar
```
# 建立程式捷徑
1. 在 /usr/share/applications/ 建立 burpsuite.desktop,內容如下:
```
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Icon=/opt/burpsuite/burpsuite.png
Exec=sh -c java -jar burpsuite_v1.7.37.jar
Name=Burp Suite 1.7.37
Path=/opt/burpsuite
Categories=03-webapp-analysis;03-06-web-application-proxies;
```
2. 設定為可執行
```
root@kali:/usr/share/applications# chmod a+x burpsuite.desktop
```
# 將 Burp Suite 捷徑加到左側 Menu 中
1. 展開 Applications 選單
2. 拖放至左側選單中
# 2019-01-21 補充
當另一個帳號登入時應用程式的 icon 沒顯示,因為 icon 圖示沒有權限,所以再加設權限就可以了
```
chmod a+rw /opt/burpsuite/burpsuite.png
```
# 參考連結
* [Desktop Entry Specification](https://developer.gnome.org/desktop-entry-spec/)
* [Desktop Menu Specification](https://specifications.freedesktop.org/menu-spec/latest/index.html)
2. 設定為可執行
```
root@kali:/usr/share/applications# chmod a+x burpsuite.desktop
```
# 將 Burp Suite 捷徑加到左側 Menu 中
1. 展開 Applications 選單
2. 拖放至左側選單中
# 2019-01-21 補充
當另一個帳號登入時應用程式的 icon 沒顯示,因為 icon 圖示沒有權限,所以再加設權限就可以了
```
chmod a+rw /opt/burpsuite/burpsuite.png
```
# 參考連結
* [Desktop Entry Specification](https://developer.gnome.org/desktop-entry-spec/)
* [Desktop Menu Specification](https://specifications.freedesktop.org/menu-spec/latest/index.html)
kali linux 更換 jdk
markdown
使用 kali linux 的 brup suite 會跳出 JRE 版本 10.0.2 沒有完全測試過,可能會發生問題的訊息。
> Your JRE appears to be version 10.0.2 from Oracle Corporation Burp has not been fully tested on this platform and you may experience problems.
# 環境
* Linux kali 4.17.0-kali1-amd64 #1 SMP Debian 4.17.8-1kali1 (2018-07-24) x86_64 GNU/Linux
* Burp Suite Community Edition 1.7.35
[查看版本的參考文章](https://workerdigholes.blogspot.com/2019/01/kali.html)
# JDK 更換或安裝
1. 查看和更改 kali linux 中的 JDK
```
update-alternatives --config java
update-alternatives --config javac
```
2. 如果要使用的JDK 不存在,安裝 JDK
```
update-alternatives --install /usr/bin/java java /opt/jdk-9.0.1/bin/java 300
update-alternatives --install /usr/bin/javac javac /opt/jdk-9.0.1/bin/javac 300
```
注意:/opt/jdk-9.0.1是自己安装的路径。
3. 安裝後再設定成要使用的版本
```
update-alternatives --config java
update-alternatives --config javac
```
選擇編號,按 Enter
4. 檢查 java 版本
```
java -version
javac -version
```
kali 查看版本
markdown
kali 查看版本
* 查看內核版本
```
uname -a
```
* 查看發行版本
```
lsb_release -a
```
執行結果
```
root@kali:~# uname -a
Linux kali 4.17.0-kali1-amd64 #1 SMP Debian 4.17.8-1kali1 (2018-07-24) x86_64 GNU/Linux
root@kali:~# lsb_release -a
No LSB modules are available.
Distributor ID: Kali
Description: Kali GNU/Linux Rolling
Release: kali-rolling
Codename: kali-rolling
```
2018-10-04
Openvas 忘記密碼重設
markdown
重設 admin 密碼
```
# openvasmd --user=admin --new-password=new_password
```
建立新帳號
```
openvasmd --create-user new_user
```
刪除帳號
```
openvasmd --delete-user=new_user
```
訂閱:
意見 (Atom)