[add] First

This commit is contained in:
建喵 2022-07-27 16:33:37 +08:00
commit 058ef57305
8 changed files with 496 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
composer.phar
/vendor/

22
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,22 @@
{
// 使 IntelliSense
//
// : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9010
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9010
}
]
}

27
Publisher Normal file
View File

@ -0,0 +1,27 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFQAAAAdzc2gtcn
NhAAAAASMAAAEBAN+nL0heoNxH1P2d9GfI7FQHHC8YMCe4C8t4kmUz3KP9jiF5kSVezId0
N/G3pOby4iB+5eKtLO9CfpUMOFXjPigSzsFLuefIWHUzCQ/3BgldBJUO1d8kW+1F6sCxr5
Vfaryau5CjmeA8A8PLAUHMueRWvj6LDPwmL0nDrEwSsJgWxcVCUlku/B87GQ738gLo5mWB
+U7zRf9KM/41aRJeOVv1bqnbu0S7HWn8iDx5d35IP3DkJPef9jxXV1T81xeyLIR+BuSYwp
umnhyewHL4uB5Ht32U71h554KtdMXWZa2rFW2RSBoX0L7aMb3mf1CiVDoCh0+XJ0uGNiH+
2xLBaokAAAPQvi1HcL4tR3AAAAAHc3NoLXJzYQAAAQEA36cvSF6g3EfU/Z30Z8jsVAccLx
gwJ7gLy3iSZTPco/2OIXmRJV7Mh3Q38bek5vLiIH7l4q0s70J+lQw4VeM+KBLOwUu558hY
dTMJD/cGCV0ElQ7V3yRb7UXqwLGvlV9qvJq7kKOZ4DwDw8sBQcy55Fa+PosM/CYvScOsTB
KwmBbFxUJSWS78HzsZDvfyAujmZYH5TvNF/0oz/jVpEl45W/V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IVATE KEY-----

1
authorized_keys Normal file
View File

@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA36cvSF6g3EfU/Z30Z8jsVAccLxgwJ7gLy3iSZTPco/2OIXmRJV7Mh3Q38bek5vLiIH7l4q0s70J+lQw4VeM+KBLOwUu558hYdTMJD/cGCV0ElQ7V3yRb7UXqwLGvlV9qvJq7kKOZ4DwDw8sBQcy55Fa+PosM/CYvScOsTBKwmBbFxUJSWS78HzsZDvfyAujmZYH5TvNF/0oz/jVpEl45W/Vuqdu7RLsdafyIPHl3fkg/cOQk95/2PFdXVPzXF7IshH4G5JjCm6aeHJ7Acvi4Hke3fZTvWHnngq10xdZlrasVbZFIGhfQvtoxveZ/UKJUOgKHT5cnS4Y2If7bEsFqiQ==

17
composer.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "user/ssh",
"autoload": {
"psr-4": {
"User\\Ssh\\": "src/"
}
},
"authors": [
{
"name": "JianMiau",
"email": "bir840124@gmail.com"
}
],
"require": {
"phpseclib/phpseclib": "^3.0"
}
}

245
composer.lock generated Normal file
View File

@ -0,0 +1,245 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "2c9cf6f81c7570ab59150455f1cd1bfe",
"packages": [
{
"name": "paragonie/constant_time_encoding",
"version": "v2.6.3",
"source": {
"type": "git",
"url": "https://github.com/paragonie/constant_time_encoding.git",
"reference": "58c3f47f650c94ec05a151692652a868995d2938"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938",
"reference": "58c3f47f650c94ec05a151692652a868995d2938",
"shasum": ""
},
"require": {
"php": "^7|^8"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8|^9",
"vimeo/psalm": "^1|^2|^3|^4"
},
"type": "library",
"autoload": {
"psr-4": {
"ParagonIE\\ConstantTime\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com",
"role": "Maintainer"
},
{
"name": "Steve 'Sc00bz' Thomas",
"email": "steve@tobtu.com",
"homepage": "https://www.tobtu.com",
"role": "Original Developer"
}
],
"description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)",
"keywords": [
"base16",
"base32",
"base32_decode",
"base32_encode",
"base64",
"base64_decode",
"base64_encode",
"bin2hex",
"encoding",
"hex",
"hex2bin",
"rfc4648"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/constant_time_encoding/issues",
"source": "https://github.com/paragonie/constant_time_encoding"
},
"time": "2022-06-14T06:56:20+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v9.99.100",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a",
"shasum": ""
},
"require": {
"php": ">= 7"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*",
"vimeo/psalm": "^1"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"polyfill",
"pseudorandom",
"random"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/random_compat/issues",
"source": "https://github.com/paragonie/random_compat"
},
"time": "2020-10-15T08:29:30+00:00"
},
{
"name": "phpseclib/phpseclib",
"version": "3.0.14",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "2f0b7af658cbea265cbb4a791d6c29a6613f98ef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/2f0b7af658cbea265cbb4a791d6c29a6613f98ef",
"reference": "2f0b7af658cbea265cbb4a791d6c29a6613f98ef",
"shasum": ""
},
"require": {
"paragonie/constant_time_encoding": "^1|^2",
"paragonie/random_compat": "^1.4|^2.0|^9.99.99",
"php": ">=5.6.1"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"suggest": {
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"type": "library",
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib3\\": "phpseclib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Wigginton",
"email": "terrafrost@php.net",
"role": "Lead Developer"
},
{
"name": "Patrick Monnerat",
"email": "pm@datasphere.ch",
"role": "Developer"
},
{
"name": "Andreas Fischer",
"email": "bantu@phpbb.com",
"role": "Developer"
},
{
"name": "Hans-Jürgen Petrich",
"email": "petrich@tronic-media.com",
"role": "Developer"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
}
],
"description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
"homepage": "http://phpseclib.sourceforge.net",
"keywords": [
"BigInteger",
"aes",
"asn.1",
"asn1",
"blowfish",
"crypto",
"cryptography",
"encryption",
"rsa",
"security",
"sftp",
"signature",
"signing",
"ssh",
"twofish",
"x.509",
"x509"
],
"support": {
"issues": "https://github.com/phpseclib/phpseclib/issues",
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.14"
},
"funding": [
{
"url": "https://github.com/terrafrost",
"type": "github"
},
{
"url": "https://www.patreon.com/phpseclib",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib",
"type": "tidelift"
}
],
"time": "2022-04-04T05:15:45+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

42
index.php Normal file
View File

@ -0,0 +1,42 @@
<?php
include_once('vendor/autoload.php');
header("Content-type:text/html;charset=utf-8");
use phpseclib3\Crypt\RSA;
use phpseclib3\Net\SSH2;
use phpseclib3\Crypt\PublicKeyLoader;
echo("<title>打包機遊戲列表</title>");
echo "打包機遊戲列表<br>";
$ssh = new SSH2('192.168.5.108', 22);
$public_key = file_get_contents(__DIR__."\authorized_keys");
$private_key = file_get_contents(__DIR__."\Publisher");
$key = PublicKeyLoader::load($private_key);
if ($ssh->login('Publisher', $key)) {
// echo('Connected');
} else {
die('Login Failed');
}
$dir = $ssh->exec('dir /b/on D:\Casino-Core-Type2\assets\Game');
$dirs = explode("\n",$dir);
function lensort($a,$b){
return strlen($a)-strlen($b);
}
usort($dirs,'lensort');
for ( $i=0 ; $i<count($dirs); $i++ ) {
$dirname = $dirs[$i];
if (strpos($dirname, "Game_") !== false && strpos($dirname, ".meta") === false) {
$gamedir = $ssh->exec('dir /b/on D:\Casino-Core-Type2\assets\Game\\'.$dirname);
$gamedirs = explode("\n",$gamedir);
if ( count($gamedirs) > 2 ) {
echo $dirname . "<br>";
}
}
}
?>

140
ssh2.php Normal file
View File

@ -0,0 +1,140 @@
<?php
// ssh protocols
// note: once openShell method is used, cmdExec does not work
class ssh2
{
private $use_pubkey_file = false;
private $host = '192.168.5.108';
private $user = 'Publisher';
private $port = '22';
private $password = 'Publisher';
private $con = null;
private $shell_type = 'xterm';
private $shell = null;
private $log = '';
public function __construct($use_pubkey_file = false, $host = '', $port = '')
{
if ($host != '') {
$this->host = $host;
}
if ($port != '') {
$this->port = $port;
}
if ($use_pubkey_file != '') {
$this->use_pubkey_file = $use_pubkey_file;
}
$methods = [];
if ($this->use_pubkey_file) {
// $methods['hostkey'] = 'ssh-rsa';
$methods = array(
'hostkey'=>'ssh-rsa,ssh-dss',
// 'kex' => 'diffie-hellman-group-exchange-sha256',
'client_to_server' => array(
'crypt' => 'aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc,blowfish-cbc',
'comp' => 'none'),
'server_to_client' => array(
'crypt' => 'aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-cbc,blowfish-cbc',
'comp' => 'none'));
}
// $this->con = ssh2_connect($this->host, $this->port);
$this->con = ssh2_connect($this->host, $this->port, $methods);
if (!$this->con) {
$this->log .= "Connection failed !";
}
}
public function authKey($pubkey_filePath, $privkey_file_filePath)
{
if ($pubkey_filePath == '') {
return;
}
if ($privkey_file_filePath == '') {
return;
}
$rc = ssh2_auth_pubkey_file($this->con, $this->user, $pubkey_filePath, $privkey_file_filePath);
return;
}
public function authPassword($user = '', $password = '')
{
if ($user != '') {
$this->user = $user;
}
if ($password != '') {
$this->password = $password;
}
if (!ssh2_auth_password($this->con, $this->user, $this->password)) {
$this->log .= "Authorization failed !";
}
}
public function openShell($shell_type = '')
{
if ($shell_type != '') {
$this->shell_type = $shell_type;
}
$this->shell = ssh2_shell($this->con, $this->shell_type);
if (!$this->shell) {
$this->log .= " Shell connection failed !";
}
stream_set_blocking($this->shell, true);
}
public function writeShell($command = '')
{
fwrite($this->shell, $command . "\n");
}
public function cmdExec()
{
$argc = func_num_args();
$argv = func_get_args();
$cmd = '';
for ($i = 0; $i < $argc; $i++) {
if ($i != ($argc - 1)) {
$cmd .= $argv[$i] . " && ";
} else {
$cmd .= $argv[$i];
}
}
echo $cmd;
$stream = ssh2_exec($this->con, $cmd);
stream_set_blocking($stream, true);
return stream_get_contents($stream);
}
public function getLog()
{
return $this->log;
}
public function getResult()
{
$contents = '';
while (!feof($this->shell)) {
$contents .= fgets($this->shell);
}
return $contents;
}
}