網頁

2022年10月11日 星期二

Windows Server 持定目錄繼承權限調整

持定根目錄,例如 D:\ 內的使用者權限包含Everyone ,但建立在 D:\Apache\ 的又不要繼承 D:\ 已有的 Everone 權限時,可採以下設定方式。

做法如下:

  1. 針對調整的目錄利用檔案總管點選該目錄,此時選擇上方功能列內的 共用」後再選取進階安全性設定
  2. 出現階安全性設定」視窗後,停用繼承項目。出現的視窗提示選取 將繼承的權限轉換成此物件中的明確權限
  3. 選擇要移除權限帳號的主體(例如:Everyone),按下確定即可 (不需要勾選最下方可供勾選的項目 "以可從此物作繼承的權限項目取代所有子物件的權限項目(p)")

這樣就設定完成了。如果要重設,可以直接將調整好的目錄刪除後再重新建立該目錄後再重新執行以上流程就可以。

2022年7月21日 星期四

7-zip plugin (SHA512)

主要是要新增 SHA 512 的功能。

  1. 下載後,直接在 7-zip 目錄內新增  Codecs 目錄並複製 WinCryptHashers.64.dll 與 WinCryptHashers.ini到該目錄。
  2. 修改WinCryptHashers.ini。將需要的 SHA-512 啟用即可 (e.g. SHA-512=1)。

相關資料:

2022年6月29日 星期三

PGP Signature 驗證@ Windows

採用 Gpg4win 的做法: 
  1. Gpg4win 下載 後直接做安裝
  2. 以 Veracrypt 軟體為例。首先到 Veracrypt 下載 安裝檔案、 PGP Signature 檔案 與 VeraCrypt PGP public key
  3. Signature 驗證:
    • 執行 Gpg4win Kleopatra
    • 建立個人 OpenPGP 金鑰配對 (Key Pair Creation Wizard),輸入名稱與電子郵件後直接點選 "Create 建立"
    • 點選 Import 功能,將  VeraCrypt_PGP_public_key.asc Import。
    • 此時會在 All Certificates 項目看到匯入的資料,點選 "VeraCrypt Team (2018 - Supersedes Key ..." 項目會出現 Certificate Details 視窗。點選視窗內的 Certify 按鈕。將自已產生的 Key 與 "VeraCrypt Team (2018 - Supersedes Key ..." 項目做 "保證" 動作。
    • 點選 "解密/檢查" 項目功能。點選要確認的 .sig 檔案 (如,VeraCrypt Setup 1.25.9.exe.sig) 後就能看到驗證成果。

其它做法:

  1. 下載 GPG Plugin Portable 。安裝後將 GPG 目錄設定在系統內設定環境變數方便使用。或是安裝Gpg4win後也可以直接在終端機直接下指令
  2. 指令參考:
  • gpg.exe --import VeraCrypt_PGP_public_key.asc
  • gpg.exe --verify VeraCrypt Setup 1.25.9.exe.sig VeraCrypt Setup 1.25.9.exe
  • 執行後有顯示 gpg: Good signature 表示OK

gpg 指令參考

  • gpg --import key..asc
  • gpg --list-keys
  • gpg --delete-key 'veracrypt@idrix.fr'

參考文件

2022年5月12日 星期四

Windows Server 關機按鈕關閉

避免誤按關閉按鈕造成主機關機。

方式一:gpedit.msc 將關機按鈕從清單內直接移除

User Configuration > Administrative Templates > Start Menu and Taskbar. > Remove and prevent access to the Shut Down, Restart, Sleep, and Hibernate commands


方式二:cmd > logoff or shutdown -l

 

相關連結:

2021年11月16日 星期二

透過 private key 免帳密直接登入 SSH

 步驟:

  1. ssh-keygen -t rsa 產生 id_rsa & id_rsa.pub
  2. mv | cat | rename ~/.ssh/id_rsa.pub ~/.ssh/authorized_key
    • 此情境是在伺服器端處理,也可在客戶端產生後將 public key 資訊傳到伺服器端
    • 若有多筆公鑰內文可以附加到 authorized_key 檔案
    • 若 SSH 伺服器是 Window OpenSSH 且登入的帳號是屬於管理者身份。那就要將 id_rsa.pub 內文附加到 C:\ProgramData\ssh\administrators_authorized_keys 檔案內。
  3. id_rsa 傳給客戶端。客戶端將該檔放在 USERPROFILE\.ssh\* 就可以直接透過 SSH 免帳密直接登入使用 (e.g. ssh sftp@192.168.0.2)
  4. id_rsa 透過 puttygen (Tools bar: Conversions item) 轉換成 id_rsa.ppk
    • puttygen Tools Bar : Conversions item
    • Load id_rsa files and choice "Save private key" item
  5. 使用方式
    • 將 id_rsa.ppk 轉給 client 使用。如透過 filezilla client,登入形式採用金鑰,金鑰指向 id_rsa.ppk
    •  id_rsa (不用轉換 ppk ) 直接放到 windows 的使用者目錄內 (如,C:\Users\user_account\.ssh)後,再直接輸入 ssh user_account@IP 即可直接登入遠方主機
  6. 指定使用者產生供使用的 private key
    runas /user:account cmd,開啟視窗後,輸入密碼。以該身份執行以上的程序即可(authorized_keys 檔案放在該登入帳號的 .ssh 目錄內)。

備忘:公鑰與私鑰的製作可以在使用者端或是伺服器端。將公鑰放到伺服器端且將私鑰傳給要連線的客戶端。

相關參考:

 

2021年11月11日 星期四

filezilla server 1.1.0 安裝備忘

新版本 v 1.1.0 舊版本 v 0.9.60_b 的介面差異很大。 

在舊版本已存在的狀態下直接做新版本的安裝會自動透過 filezilla-server-config-converter.exe 自動轉換成新版本所採用的設定檔。轉換上去後,在 passive mode settings 的部份沒有順利轉換上去,需要自行重新設定,其它的部份看來都有正確的轉換。

安裝完畢後進入介面的 configure 項目做以下設定調整:

FTP Server Listeners :
Protocol 的部份全部改成  Require explicit FTP over TLS (port 990 可以關閉)

Passive mode:
需要自行重新設定

Security:
Provide a X.509 certificate,憑證的產生方式已沒有內建,可利用 openssl 自行產生。或者直接採用 filezilla server 所提供的憑證 “Use a self-signed X.509 certificate” 來做使用。先前舊版本的憑證可以透過 filezilla server 自已提供的功能產生,但它的做法會將 RSA PRIVATE KEY、CERTIFICATE 放在同一個檔案,如果要照舊那就產生的 key and crt 的內容合併在一起即可。

設定檔備份:
新版本設定檔的部份調整放到 C:\Windows\System32\config\systemprofile\AppData\Local\filezilla-server

Daemon 執行身份調整 (e.g. account_ftp user):預設安裝時會將設定檔放到上面所指定的位置。於系統服務將該 daemon 切換執行身份後會在新設定的身份的  C:\New_User\AppData\Local\filezilla-server\* 新增 filezilla server 的設定檔案。將 \filezilla-server\* 目錄賦予相關使用者寫入的權限後再將目錄內已存在的相關設定檔直接刪除再由原來已設定完成(C:\Windows\.....)的設定檔案複製過來。重新啟動 filezilla server 服務。這不確定有沒有其它更簡便的切換方式,爾後再確認。

版本更新方式:下載新版本後(e.g. 1.5.0 version),直接點選執行檔。重新按介面提示重新安裝一次。但更新後它的 daemon 於系統服務內的登入身份會轉換到執行更新時的帳號身份。若採不同身份執行特定 deamon 的做法時,記得將身份切換回所要指定的身份。

Logging:
先新增 ftp_log.txt 後再到介面內將 File path 指向這個檔案;log output 選用 To file.

目前使用狀況:
使用起來都OK。但 client 連線使用完畢做切斷的動作會出現以下訊息。這在舊版本沒有出現。
GnuTLS error -110 in gnutls_record_recv: The TLS connection was non-properly terminated.
Client did not properly shut down TLS connection
Control channel closed with error from source 0. Reason: ECONNABORTED - Connection aborted.
Session 1 ended with error from source 0. Reason: ECONNABORTED - Connection aborted.

note : 此問題已於 1.4 版本修正

FTPstats GUI-based FileZilla log parser : 待找
 

2021年11月5日 星期五

PHP Curl SSL certificate problem

 

CA files 

PHP.ini

curl.cainfo="C:\php\extras\ssl\cacert.pem"

PHP code

//Tell cURL where our certificate bundle is located.
$certificate = "C:\php\extras\ssl\cacert.pem";
curl_setopt($ch, CURLOPT_CAINFO, $certificate);
curl_setopt($ch, CURLOPT_CAPATH, $certificate);

 

相關資料:

2021年11月2日 星期二

批次壓縮檔案與建立目錄內檔案清單

 zip.bat

rem 使用方式:檔案拖拉到此批次檔案即可
rem 此機制會自動在檔案名稱後加入副檔名名稱, 如 .pdf.zip。再利用批次重新命名修改即可
@echo off
set "a=%ProgramFiles%\7-zip\7z.exe"
for %%a in (%*) do if exist "%%~a\" (
        "%a%" a -tzip "%%~a.zip" "%%~a\*" -mx7
        ) else (
        "%a%" a -tzip "%%~a.zip" "%%~a" -mx7
        )

 list.bat 

rem 列出檔案名稱並依照檔名排序
rem 使用方式:檔案拖拉到此批次檔案即可
dir /b /on > list.txt

2021年7月21日 星期三

Apache CGI

httpd.conf example

<Directory "C:/Apache2/cgi-bin">
    #AllowOverride None
    #Options None
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl
    Require all granted
</Directory>

cgi or perl 程式需要放到指定的 cgi-bin 目錄內執行。 很多 cgi 或 perl  都是採用 #!/usr/bin/perl 的宣告 。所以避免修改原有程式可以將 active perl 安裝於 C:\usr\ 目錄內,這樣就不需要修改現有程式。若是按 perl 預設安裝路徑那就需要修改為 #!C:\Perl64\bin\perl.exe。

相關參考:

2021年3月9日 星期二

SFTP 安裝@ Windows

步驟 

@windows

應用程式內新增 OpenSSH伺服器

@powershell

Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

Get-NetFirewallRule -Name *ssh* //檢視規則

New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 //調整規則

調整 ssh_config 檔案 (%programdata%\ssh) & restart sshd

Port 22
ForceCommand internal-sftp //強制僅使用 sftp connections
Subsystem    sftp    sftp-server.exe -d "C:\Data_SFTP\"
ChrootDirectory C:\Data_SFTP //指定連線到特定目錄

AllowUsers sftpuser //加強管理
AllowGroups sshusers //加強管理

Logging //Windows OpenSSH 預設會記錄在事件檢視器。若要調整為記錄於檔案內需做以下調整。

SyslogFacility AUTH | LOCAL0 //AUTH 記錄在事件檢視器;LOCAL0 記錄在檔案
LogLevel INFO | VERBOSE | Debug3  (視需求)

//針對特定的 group 限制(系統內新增 sftponly group,並設定指定受限帳號)
Match Group sftponly
       ChrootDirectory C:\Apache2\htdocs
       ForceCommand internal-sftp
       X11Forwarding no
       AllowTcpForwarding no
 
//針對指定帳號登到指定目錄
Match User sftp_user
       ChrootDirectory C:\Apache2\htdocs\sftp_user
       ForceCommand internal-sftp
       X11Forwarding no
       AllowTcpForwarding no


參考資料

2021年2月18日 星期四

透過Adguard 阻擋Youtube APP廣告

Adguard 若僅透過瀏覽器使用 Youtube 觀看影片,它的阻擋廣告效果很好但在手機上直接透過 Youtube APP 觀看影片的效果有限。

現在 Adguard 有提供一個方式可有效阻擋廣告,在操作上也僅需要幾個步驟即可。

Android 或 iOS 使用 Youtube APP 操作上僅有兩個步驟:

  1. Open YouTube app and start the video you want to watch. (在 youtube APP 打開要看的影片)
  2. Tap on the Share button and select AdGuard for Android from the list of apps. (在分享按鈕那點一下分享給Adguard 即可) 

相關參考:


2021年2月6日 星期六

Apache SSL Cipher Suite

加密演算法也是資安的評量點。

設定的參考可以使用 moz://a SSL Configuration Generator 所建議的 Cipher Suite 設定。

設定值:

SSLProtocol -all +TLSv1.2 +TLSv1.3 //刪除所有的 protocol 並加入 TLSv1.2 , TLSv1.3

也可以這樣子寫

SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1 // 使用所有的 protocol 不使用SSLv3 ,TLSv1,TLSv1.1

SSLProxyProtocol  (與 SSLCipherSuite 的設定相同)

SSLCipherSuite       ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 

SSLProxyCipherSuite       (與 SSLCipherSuite 的設定相同)

SSLUseStapling On    //加快 SSL certificate 驗証

其它設定

    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"

 

檢測 SSL Cipher 檢測工具

  • nmap : e.g. nmap --script ssl-enum-ciphers -p 443 Server_IP -P0 | find "EXP"
  • sslscan windows

 

參考資料:


2020年11月20日 星期五

youtube-dl

基本上也是因為新聞才注意到此工具。基本上類似這類的工具不少,透過一些線上平台的服務使用就有相同的功能,使用上只要在平台頁面內貼上要下載的網址就可以下載。有些安裝在電腦內的付費版本軟體則有額外再提供轉檔等功能 (如,MP4 轉 MP3)。但這些功能 youtube-dl 也都有提供,且它也不僅只有支援 youtube 平台,它所支援的影音平台眾多。

簡單的註記使用方式:

下載: 

youtube-dl webiste , windows UI Portable

 外掛(有轉檔需求才需要):

ffmpeg, ffmpeg windows (ffmpeg-N-99931-ge3081d6f4f-win64-gpl-shared-vulkan 39.2MB ,不是很明白不同版本的差異,我是找容量最小的版本使用)

設定方式(@ windows): 

將下載的檔案放到指定的位址。設定作業系統內的環境變數,Path 路徑指定到程式放的位置。

軟體更新:

youtube-dl -U

使用範例:

youtube-dl <url> (自動會取最佳畫質)
youtube-dl <url> -F (看看有那些格式可以下載)
youtube-dl <url> -f 22+140 (指定要的格式與聲音下載 ; 數字由 -F 所呈現的資訊決定)
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' <url> (直接讓程式決定自動下載最佳所指定的影片+聲音 ; Download best mp4 format available or any other best if no mp4 available)
youtube-dl -x --audio-format mp3 <url> (直接抓取 mp3)
youtube-dl -x --audio-format mp3 --embed-thumbnail --add-metadata <url> (轉檔成mp3並加入縮圖與影片資訊)
youtube-dl -f mp4 <playlist-url>  (下載整份影片清單)
youtube-dl <url1> <url2> <url3> (下載多個指定的影片)
youtube-dl -f best -a list.txt (按檔案內的清單下載)
youtube-dl -f best <url>
youtube-dl -f 'bestvideo+bestaudio/bestvideo+bestaudio' --merge-output-format mp4 <url>
youtube-dl -f 'bestvideo[ext=webm]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 <url>
youtube-dl -f 'bestvideo+bestaudio[ext=m4a]' --merge-output-format mp4 <url>

下載 facebook 不開放社團內影片 youtube-dl --username=your account email --password=yourpassword https://www.facebook.com/video_URL

111.02.18 不知為什麼採上以上方式會出現 This video is only avaliable for registered user. 但確認登入的帳密是有效的。後來改用 cookie 的方式來抓取

cookie 的方式:

1. export cookie txt files (e.g. firefox export cookie puglin),保留 facebook cookie 即可。

2. youtube-dl --cookies C:\Temp\cookie.txt <facebook video url>

ffmpeg 影片切割
ffmpeg -ss 00:00:30.0 -i input.mp4 -c copy -to 00:01:30.0 output.mp4 (起訖時間;訖的時間由起開始計算)

教學參考:

  1. How to Install Youtube-DL on Windows
  2. youtube-dl Format Selection 
  3. 用 youtube-dl 優雅下載 YouTube 影片 
  4. Youtube-dl濃縮教學筆記 
  5. shell - youtube-dl DASH視頻和音頻,無需人工干預即可獲得最高質量  
  6. 影音剪輯 / 使用 ffmpeg 分割影片 (指定開始及結束時間或固定時間長度分割)
  7. FFmpeg无损快速切割视频方法 
  8. 懶人剪影片法(使用終端機指令)

注意事項: 

  1. 下載Youtube音樂或影片合法嗎?
  2. MP3音樂檔案下載是否違法?
  3. [法律授權] 我可以在自己的網站上使用那支影片嗎? Youtube、Vimeo、Vine,Instgram
  4. 你以為的 YouTube 無版權音樂竟然侵權?讓創作者苦惱的著作權問題
  5. 鏈結youTube影片不構成侵害著作權 ?
  6. 盜版線上看,不下載不犯法? 
  7. 【法律白話文運動】線上的盜版影片違反著作權法,那我線上追劇有沒有違法? 


2020年10月11日 星期日

調整相片 exif 日期

Example:

exiftool "-DateTimeOriginal+=9:9:7 02:42:0" "D:\pics_1091009\1091009"
exiftool "-DateTimeOriginal+=9:9:7 02:42:0" "D:\pics_1091009\1091010"

說明:針對目錄 1091009 內的檔案,時間加上 9:9:7 (9 年 9 個月 7 天)以及 02:42:0 (2 個小時 42 分 0 秒)

軟體下載:

https://exiftool.org/

相關參考:

https://exiftool.org/#shift

https://jerome.anyday.com.tw/archives/143


2020年8月14日 星期五

Lotus Notes 快速設定

 將 C:\Users\account\AppData\Local\IBM\Notes\Data\* 內的檔案全數複製到新的主機內即可。

2020年7月17日 星期五

MySQL 多版本並存 @ Windows

同主機內多版本 MySQL並存安裝方式:

下載 MySQL instraller ,點選並執行它。安裝過程參考附圖。過程中要注意的事項如下:
  1. 由於是要同主機多版本並存使用,所以 installer 的第一個頁面要選擇 Cancel後,再點選 Add 按鈕 (圖二)。
  2. port 衝突的問題,記得預設 port 號要更改。
  3.  Authentication Method 更動,主要是考量到版本相容性而已。
附圖參考:



















相關參考:

2020年5月20日 星期三

LDAP 相關資料



LDAP Code example

https://www.exchangecore.com/blog/using-ldap-active-directory-authentication-php

https://github.com/anthony-b/simple-php-LDAP-Authentication/blob/master/ldap.php

https://www.php.net/manual/en/ref.ldap.php

https://icodding.blogspot.com/2015/10/php-php-ad-server.html?m=0

https://www.php.net/manual/en/function.ldap-get-option.php

PHP 7.1 added support for configuring the LDAP CA/Cert environment directly

ldap_set_option(NULL, LDAP_OPT_X_TLS_CERTFILE, "/path/file.crt");

ldap_set_option(NULL, LDAP_OPT_X_TLS_KEYFILE, "/path/file.key");

https://bojack.pixnet.net/blog/post/23832296-%E3%80%90%E7%A8%8B%E5%BC%8F%E3%80%91%E5%88%A9%E7%94%A8-php-%E6%90%9C%E5%B0%8B-ldap---ad-%E8%B3%87%E8%A8%8A

https://ithelp.ithome.com.tw/questions/10167400

https://shuohsuanli-bear.blogspot.com/2016/11/phpactive-directory.html


LDAP Intro.

https://segmentfault.com/a/1190000014683418

https://blog.tomy168.com/2019/07/centos76-openldap.html

https://blog.xuite.net/tolarku/blog/151029105-LDAP+%E5%9F%BA%E7%A4%8E%E8%AA%AA%E6%98%8E

https://itman.pixnet.net/blog/post/26817279

https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/77626/


LDAP Online Test Server

https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

https://www.youtube.com/watch?v=AEjGhzZpGlg


LDAP Tools

Apache Directory Studio.

phpLDAPadmin

LDAP Admin

More
The Difference Between Active Directory and LDAP

2020年2月11日 星期二

cygwin 檔案及目錄設定不同權限的做法

按原 cygwin 的預設預設權限權限方式為目錄 770 檔案 750 ,但不知為什麼有少數幾台主機所使用的目錄與檔案預設權限都是 770 (查詢 umask 後都是正確的 0022)。

可以使用以下方式直接重設想要的權限:

使用 find 來執行 chmod:

find Apache2/ -type d -exec chmod 770 {} \; <= /www 內所有目錄
find Apache2/ -type f -exec chmod 750 {} \; <= /www 內所有檔案

find 的 -type 參數可以指定檔案的類型,常用的選項有:

d:目錄。

p:具名的 pipe(FIFO)。

f:一般的檔案。

l:連結檔,如果與 -L 或 -follow 參數同時使用時,就只會搜尋到有問題的連結檔,如果想要與 -L 同時使用,請改用 -xtype。

s:socket 檔案。

其它用的到的 find 指令

//找出當下目錄權限為 777 的所有檔案

find . -type f -perm 0770

//找出當下目錄權限不是 777 的所有檔案
find . -type f ! -perm 0770
雜記

目前遇到的狀況是在 htdocs 目錄內新增的檔案或目錄的權限會變成 ---rwx--- 的權限異常狀況。這也是為什麼會有這篇的存在。

發生原因不明,查看 umask 的預設設定皆正常,後來乾脆將 htdocs 目錄刪除,再利用 ssh ftp 帳號登入後,用這個身份新增目錄(e.g. mkdir htdocs),這時在這個特定的 htdocs 目錄內所新增的權限就是預設給的權限。


相關參考: