ラベル ProcessMakerTL の投稿を表示しています。 すべての投稿を表示
ラベル ProcessMakerTL の投稿を表示しています。 すべての投稿を表示

2018年6月3日日曜日

悪用厳禁:別のPCのデスクトップ画面をキャプチャ。|PowerShell

別のPCのデスクトップ画面をキャプチャ。

Windows|PowerShell
Mac OS でも出来なくはない。

ProcessMakerTLの準備。

デスクトップ画面をキャプチャしたいPCに「ProcessMakerTL」を設定。

ProcessMakerTL をダウンロード
download - ProcessMakerTL : https://sites.google.com/site/processmakertl/download

任意の場所に展開。
例: C:\ProcessMakerTL

試用認証キーファイル をダウンロードして ProcessMakerTL.key を ProcessMakerTL.exe と同じ階層に保存。

起動用バッチファイル(*.bat)を作成。
ファイル名:StartProcessMakerTL.bat
内容:
cd /d %~dp0
"ProcessMakerTL.exe" "address=*" "port=8081" "access_token=0123"

ProcessMakerTL.exe と同じ階層に保存。



StartProcessMakerTL.bat をダブルクリックし、ProcessMakerTL.exe を起動。
※起動しない場合は、以下を確認。

以下のようになれば、起動OK.
ProcessMakerTL_Server:1.1.0.0
Fire >
activation:True
Server Started: 0.0.0.0:8081
access_token: presence

ブラウザで http://127.0.0.1:8081/ にアクセスしてみましょう。
Invalid API token と表示されます。access_tokenを設定して、ProcessMakerTLを起動しているので、エラーになりますが、正常に動作しています。


別のPCから動作チェック。
別のPCのブラウザでProcessMakerTLを起動しているPCのIPアドレスを入力してみましょう。
ブラウザで http://192.168.0.9:8081/ にアクセス。
※ProcessMakerTLを起動しているPCのIPアドレスが 192.168.0.9 の場合。
Invalid API token と表示されればOK。

デスクトップ画面をキャプチャするPowerShellを準備。
以下は、デスクトップ画面をキャプチャし、Base64を返すPowerShellのコードです。

Add-Type -AssemblyName System.Windows.Forms ;
Add-Type -AssemblyName  System.Drawing  ;
$rect = [System.windows.forms.Screen]::PrimaryScreen.Bounds;
$bitmap = new-object System.Drawing.Bitmap( $rect.Width, $rect.Height, [System.Drawing.Imaging.PixelFormat]::Format32bppArgb);
$graphics = [System.Drawing.Graphics]::FromImage($bitmap);
$graphics.CopyFromScreen( $rect.X, $rect.Y, 0, 0, $rect.Size, [System.Drawing.CopyPixelOperation]::SourceCopy);
$memStream = New-Object System.IO.MemoryStream;
$bitmap.Save($memStream,[System.Drawing.Imaging.ImageFormat]::Png );
[byte[]]$bytes = $memStream.ToArray();
$result=([convert]::ToBase64String($bytes)).ToString();
Write-Output  $result;

ファイル名:capture_base64.ps1 でProcessMakerTL.exe と同じ階層に保存。

別のPCのブラウザでURLに以下をコピペして実行してみましょう。

http://192.168.0.9:8081/?target=PowerShell&Arguments=iex%20(Get-Content%20capture_base64.ps1%20-Raw)%3B&access_token=0123
※192.168.0.9 は、ProcessMakerTLを起動しているPCのIPアドレスに変更してください。
以下のように BASE64 の文字列が表示されればOK。

別のPCで ProcessMakerTL.exe を起動しているPCの画面を取得してPNGファイルを保存するPowerShellスクリプトを実行。

Windows PowerShell ISE を起動。

以下のスクリプトを実行。

$body=@{};
$body.Add("target","PowerShell");
$body.Add("Arguments","iex (Get-Content capture_base64.ps1 -Raw);");
$body.Add("access_token","0123");
$return=Invoke-RestMethod -Method GET -Uri http://127.0.0.1:8081 -body $body;
$base64= $return;
$dir = 'C:\Users\PCUSER\Desktop\!Temp\capture\'
$filename = Get-Date -Format "yyyy-MMdd-HHmmss"
$bytes = [Convert]::FromBase64String($base64)
[IO.File]::WriteAllBytes($dir+"capture_$filename.png", $bytes)


C:\Users\PCUSER\Desktop\!Temp\capture\ に画像が保存されます。
※$dir = 'C:\Users\PCUSER\Desktop\!Temp\capture\' は、任意の場所に書き換えてください。

ProcessMakerTL.exe をバックグラウンドで起動。
タスクスケジューラでシステム起動時にProcessMakerTL.exe を起動するように設定しておくとProcessMakerTL.exe がバックグラウンドで起動します。

操作:プログラムの開始
プログラム/スクリプト
C:\ProcessMakerTL\ProcessMakerTL.exe
引数の追加
 "address=*" "port=8081" "access_token=0123" "WindowStyle=Hidden"

※引数に "WindowStyle=Hidden" を加えると ProcessMakerTL.exe は、非表示の状態で起動します。