2022年12月18日 星期日

RDP to Ubuntu desktop

Reference:
 
apt install xfce4 xrdp
systemctl enable xrdp
adduser xrdp ssl-cert
vi /etc/xrdp/startwm.sh
新增紅色部分
 
if test -r /etc/profile; then
        . /etc/profile
fi

startxfce4
test -x /etc/X11/Xsession && exec /etc/X11/Xsession
exec /bin/sh /etc/X11/Xsession
 
重新啟動service
systemctl restart xrdp
 
修改登入帳號user1的 .xsession
su - user1
echo xfce4-session > ~/.xsession
 
PS. GNOME desktop沒測試出來

Ubuntu 22.04.1 install ssh server

Reference:
Ubuntu 安裝與設定 ssh server
 
Ubuntu 22.04.1預設沒有 sshd,安裝指令:
apt install openssh-server -y

確認sshd運行狀況:
systemctl status ssh

如果要讓root可以用ssh連上:
vi /etc/ssh/sshd_config
加上 PermitRootLogin yes
systemctl restart ssh

2022年12月2日 星期五

CentOS Gnome xwindow 縮小後消失的處理方法

Reference:

狀況:
xwindow 縮小後消失

解法:
Right-click on the "task bar", click "Add to Panel", select "Window List" and "Add". 


2022年10月7日 星期五

Run powershell with TaskSchd 工作排程器

Reference:
 
在工作排程器執行 powershell,不能直接指定 ps1 檔案。
 
設定方法:
需要在「程式或指令碼」打powershell
「新增引數」打-file “C:\script\import.ps1” 才能正常運行
 

2022年10月3日 星期一

Powershell Script for Microsoft SQL server

Reference:
 
#連線資料庫
$serverName = "SQL01"
$databaseName = "wiside"
$tableName = "dbo.raw_data"
$uid = 'sa'
$pwd = 'mypassword'

$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "server='$serverName';database='$databaseName';User ID = $uid; Password = $pwd;"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection

$insertquery="INSERT INTO $tableName ([ID],[mac],[vendor],[datetime]) VALUES ('$ID','$mac','$vendor','$datetime')"
$Command.CommandText = $insertquery
$Command.ExecuteNonQuery()

$Connection.Close();

catch exception on powershell script

Reference: 

try {
    # 主要程式邏輯
}
catch [System.NotSupportedException] {
    Write-Output "不支援"
}
catch [System.IO.DirectoryNotFoundException] {
    Write-Output "找不到資料夾"
}
catch {
    Write-Output "通用的例外處理"
}

LInux samba service on CentOS 7

Reference:
 
安裝:
yum install -y samba

設定:
cp /etc/samba/smb.conf /etc/samba/smb.conf.ori
vi /etc/samba/smb.conf
 
[global]
        workgroup = SAMBA
        security = user
        #passdb backend = tdbsam

        map to guest = bad user
        #printing = cups
        #printcap name = cups
        #load printers = yes
        #cups options = raw

[images]
        comment = public images
        path = /path/to/images
        browseable = Yes
        read only = Yes
        writable = Yes
        guest ok = Yes
        force user = smbuser
 
啟動:
systemctl enable smb.service ; systemctl enable nmb.service
systemctl restart smb.service ; systemctl restart nmb.service
 
設定使用者帳號:
user add smbuser
smbpasswd smbuser
chown -R smbuser /path/to/images

2022年9月23日 星期五

Powershell get webapi data

Reference:
 
#檔案輸出指定為ascii
$PSDefaultParameterValues['*:Encoding'] = 'Ascii'

#暫存檔主檔名
$tmpfile = "E:\Tool\tmp"

#7z位置
$7z_path = 'C:\Program Files\7-Zip\7z.exe'

#用postman測試可以抓到資料後,postman可以產生對應的powershell code
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Token XXXXXXor8mWYh259gqa1ZcMa")

$response = Invoke-RestMethod 'https://backend.com.tw/blue/raw_data/?index=blue-04&time=2022-09-11T20:00:00,2022-09-11T21:59:59' -Method 'GET' -Headers $headers


#webapi的回應為 result: value,取出 value (base64格式)
$result_base64 = $response[0].result
$out_b64 = $tmpfile + ".b64"
$result_base64 | Out-File -FilePath $out_b64    #$out_b54 for debug

#decode base64 得到 .gz檔
$result_gzip = [Convert]::FromBase64String($result_base64)
$out_gz = $tmpfile + ".gz"
[IO.File]::WriteAllBytes($out_gz, $result_gzip)    #$out_gz for debug

#解壓縮 .gz
$argumentlist="x -y $($out_gz)"        # x 解壓縮,-y 回答 yes
start-process $7z_path -argumentlist $argumentlist    #解壓縮後的檔案為 $tmpfile

$out_csv = $tmpfile + ".csv"
(Get-Content $tmpfile | ConvertFrom-Json) | ForEach-Object {
    #$_.mac + "," + $_.vendor + "," + $_.datetime
    $_.address + "," + $_.company + "," + $_.upload_time
} | Out-File -FilePath $out_csv
 

Powershell script 登入網頁、執行指令 (未完成)

Reference:
 
狀況:
有一支IPCAM的NTP有問題,這家廠商已經不提供韌體更新。
登入它的管理網頁有手動同步時間,這功能正常。
我想用powershell script登入IPCAM,再click "time sync"。
但是這一支IPCAM的登入網頁用javascript,我就卡住了.....
 
使用 Powershell ISE
 
$azr = Invoke-WebRequest -Uri "http://211.72.66.73:8120/" -SessionVariable sbv
$azr
$azr|gm
$azr.Forms
$dbform = $azr.Forms["myForm"]
$dbform.Fields
$dbform.Fields["Username"] = "username"
$dbform.Fields["Password"] = "password"
$dbform.Action
$r = Invoke-WebRequest -Uri "http://211.72.66.73:8120/" -WebSession $sbv -Method Post -Body $dbform.Fields
 
 
 
 
 
 
 
 

2022年8月4日 星期四

python ImportError: cannot import name 'Sequence' from 'collections'

Reference:
 
錯誤訊息:
Traceback (most recent call last):
  File "C:\py\py_Server.py", line 27, in <module>
    from Etrigan import Etrigan, Etrigan_parser, Etrigan_check, Etrigan_job
  File "C:\py\Etrigan.py", line 12, in <module>
    from collections import Sequence
ImportError: cannot import name 'Sequence' from 'collections'
 
解法:
修改 C:\py\Etrigan.py 內容
原本
from collections import Sequence 
改為
from collections.abc import Sequence
 
 
 

2022年7月26日 星期二

在 Hyper-V 安裝 Windows 11

CPU: 64bit, 1GHz, core x 2
RAM: 4GB
Disk: 64GB
Boot: UEFI, TPM

以 Hyper-V 測試安裝,要選第2代。

Windows 11 使用 IE

Reference: 

開 notepad 輸入
CreateObject("InternetExplorer.Application").Visible=true
存檔為 IE11.vbs

修改 Edge 設定,預設瀏覽器 / 在 Microsoft Edge 中以 Internet Explorer 開啟網站
改為 "永不"

執行 IE11.vbs 即可。

2022/7/28 update:


2022年7月13日 星期三

Cadence Virtuoso IC0616 on CentOS 6

狀況:Virtuoso IC0616在CentOS 5可執行,但在CentOS 6出現錯誤訊息command not found。

原因:IC0616 需要 ksh, 32bit Xwindow lib

解法:
1. upload CentOS 6 i686 ISO to host
2. mkdir /media/CentOS/
3. mount -t iso9660 -o loop /root/CentOS-6.10-i386-bin-DVD1.iso /media/CentOS/

yum --disablerepo=\* --enablerepo=c6-media install ksh
yum --disablerepo=\* --enablerepo=c6-media install libXext
yum --disablerepo=\* --enablerepo=c6-media install libXt
yum --disablerepo=\* --enablerepo=c6-media install libGL
yum --disablerepo=\* --enablerepo=c6-media install libGLU
yum --disablerepo=\* --enablerepo=c6-media install freetype
yum --disablerepo=\* --enablerepo=c6-media install libXrender
yum --disablerepo=\* --enablerepo=c6-media install libXp
yum --disablerepo=\* --enablerepo=c6-media install glibc-devel

2022年7月6日 星期三

jmeter 對 web api 做壓力測試

Reference:
 
設定 jmeter 用 web api 取得資料做壓力測試

新增 Thread Group,執行次數等 web api 確定可以抓到資料後再調整

Check TLS version on linux host

Reference:

確認 linux web server 支援的 TLS 版本,如果有支援回應的訊息會包含憑證資訊。
#openssl s_client -connect localhost:443 -tls1
#openssl s_client -connect localhost:443 -tls1_1
#openssl s_client -connect localhost:443 -tls1_2
#openssl s_client -connect localhost:443 -tls1_3

有支援的TLS版本回應畫面

2022年7月2日 星期六

Run sublime on CentOS 6

CentOS 6 執行 sublime text 3, 4 會顯示需要 gtk 3
嘗試在 CentOS 6 安裝 gtk 3,但是還有很多相關套件要裝,最後放棄。

測試 sublime test 2 可以在 CentOS 6 執行,最後採用這版本。

2. tar jxvf Sublime\ Text\ 2.0.2\ x64.tar.bz2
3. mv Sublime\ Text\ 2 /opt/sublime2
4. ln -s  /opt/sublime2/sublime_text /usr/bin/sublime_text

2022年6月23日 星期四

CentOS install package by ISO

Reference:
 
Upload CentOS ISO file. Ex: /root/CentOS-6.10-i386-bin-DVD1.iso
 
mkdir /media/CentOS/
 
mount -t iso9660 -o loop /root/CentOS-6.10-i386-bin-DVD1.iso /media/CentOS/
 
yum --disablerepo=\* --enablerepo=c6-media install libX11.i686

CentOS install TclPro


CentOS 只能安裝到 1.4 版,因為 1.5 版只有 FreeBSD 的安裝檔。
測試 CentOS 5, 6都可以安裝。

2022年6月8日 星期三

Microsoft Teams 會議選項 / 在大廳等候

狀況:
建立Teams會議室,只有主持人可以直接進入,其他帳號都會在大廳等候,已經設定組織中的人員無須等候也不行。

2022年5月21日 星期六

Linux 密碼原則 複雜度設定

Reference:
 
設定密碼有效期限
vi /etc/login.defs
PASS_MAX_DAYS   90  # 密碼有效天數,多久要變更密碼
PASS_MIN_DAYS   1     # 變更密碼後要多久才能再修改密碼
PASS_MIN_LEN    12    # 密碼的最小長度
PASS_WARN_AGE   7  # 密碼失效之前幾天發出警告訊息

設定密碼複雜度
vi /etc/pam.d/system-auth
password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= minlen=12 minclass=4 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1

#minlen=12    密碼長度12以上
#minclass=4   包含4種類型(大寫、小寫、數字、符號)
#lcredit=-1      小寫1個以上
#ucredit=-1     大寫1個以上
#dcredit=-1     數字1個以上
#ocredit=-1     符號1個以上
 
Linux check user password expiration
chage -l userName 
 
List User Last Login on Linux
lastlog -u <user>

2022年5月16日 星期一

2022年5月9日 星期一

ELK error: maximum normal shards open

Reference:
 
原因:
ELK 一個 node 最大 index 是 1000,超過時會無法紀錄 log。
在 /var/log/messages 會看到錯誤訊息 Validation Failed: 1: this action would add [2] shards, but this cluster currently has [999]/[1000] maximum normal shards open

暫時解法:
增加 max_shards_per_node

2022年4月29日 星期五

Linux mail smtp testing

Reference:
 
從 Linux 測試寄信是否正常。
1. 安裝 ssmtp: yum install ssmtp
2. 編輯設定檔: vi /etc/ssmtp/ssmtp.conf (依照smtp server要求設定)
mailhub=smtp.gmail.com:587
useSTARTTLS=YES
AuthUser=username-here
AuthPass=password-here
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
3. 編輯設定檔: vi /etc/ssmtp/revaliases
root:username@gmail.com:smtp.gmail.com:587
4. 測試寄信: echo "Test message from Linux server using ssmtp" | ssmtp -vvv revceivers-email@gmail.com

參數 -vvv 會顯示詳細連線資訊,用以判斷寄信失敗的原因。

Outlook 開啟 pst 無信件 (Gmail IMAP)

Reference:
 
開啟 pst 後,需要調整為 IMAP檢視

 

2022年4月27日 星期三

Perl to EXE

Reference:
 
本來裝 ActivePerl 5.34,但是它不給裝 PAR::Packer (perl to exe),只好改用 Strawberry Perl
  • download Strawberry Perl and install
  • 開啟 CPAN client,執行 install PAR::Packer 安裝

2022年4月24日 星期日

2022/4/24 新竹戀戀桐花路跑

今年的戀戀桐花跑完了。
成績比去年快52秒,哈哈 ^__^|||
2019年2:33:13、2020年2:30:02、2021年2:33:44、2022年2:32:52。
明年再來!

主辦單位:中華民國陸上運動競技協會

比賽地點:合興愛情車站

2022年3月23日 星期三

2022年3月9日 星期三

Fortigate forticlient sslvpn DNS 問題

Reference:

狀況:
iPhone, iPad 使用 foticlient sslvpn 撥通後,無法開啟內部網頁。

原因:
forticlient iOS 版 bug,需用指令修改 Fortigate 設定。

解法:
用 ssh 連上 Fortigate,執行以下指令。
config vpn ssl settings
set dns-suffix "example.com;example.net;example.org"




2022年3月6日 星期日

CentOS 7 更新 sshd 版本

Reference:
 
安裝需要的工具
yum -y install wget tar gcc make perl
 
download zlib last version
到 https://zlib.net/ 確認最新版本
wget https://zlib.net/zlib-1.2.11.tar.gz

download openssl last version
到 https://www.openssl.org/source/ 確認最新版本
wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz

download openssh last version
到 https://www.openssh.com/ 確認最新版本
https://www.openssh.com/portable.html
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.9p1.tar.gz
 

2022年3月2日 星期三

FlowPortal 筆記

工作流程及簽核軟體

安裝說明

安裝準備:
  • 安裝Windows 2022
  • 安裝MSSQL 2019
  • 新增 IIS 角色 (除了FTP以外,都會用到)

2022年2月13日 星期日

Fortigate close port 2000, 5060

Reference:
 
從 CLI 調整:
config system session-helper
delete 13
end
 
config system settings
set default-voip-alg-mode kernel-helper-based
end

config voip profile
edit default
config sip
set status disable
end
end
 
清除 session:
diagnose sys session clear

再次用 nmap 測試,如果還是有 open port,
請從 GUI 檢查 System / Administrators / Trust Hosts 的設定。
先設定 Trust Hosts,再從非 Trust Hosts 測試。
因為 Trust Host 權限最大,如果 Trust Hosts 沒設定,預設全部都是 Trust Hosts。
 

2022年2月5日 星期六

Backup tool for Windows

Windows 簡易備份工具 Cobian Backup/Cobian Reflector

建議安裝 Cobian Reflector,這一版有支援 sftp。

滲透測試軟體 Burp Suite

Reference: 

本來我是用免錢的 OWASP ZAP,但是客戶說他們網站很重要,一定要用專業工具檢查。只好裝Burp Suite Professional 來檢查,可以試用 30 天。

安裝:
使用教學: 

2022年1月25日 星期二

第二雙 Y拖

2020/10/1 第一雙Y拖。

最近幾次跑完,感覺腳根不太舒服,看來它已經到極限了。
看Strava的紀錄,這雙跑了2318KM,太超值了。

2022/1/25 第二雙 Y 拖。 (SIZE: 43號)