Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../vendor/phpsecli.../phpsecli.../phpsecli.../Net
File: SSH1.php
$this->interactiveBuffer.= substr($response[NET_SSH1_RESPONSE_DATA], 4);
[1000] Fix | Delete
}
[1001] Fix | Delete
}
[1002] Fix | Delete
[1003] Fix | Delete
/**
[1004] Fix | Delete
* Inputs a command into an interactive shell.
[1005] Fix | Delete
*
[1006] Fix | Delete
* @see self::interactiveRead()
[1007] Fix | Delete
* @param string $cmd
[1008] Fix | Delete
* @return bool
[1009] Fix | Delete
* @access public
[1010] Fix | Delete
*/
[1011] Fix | Delete
function interactiveWrite($cmd)
[1012] Fix | Delete
{
[1013] Fix | Delete
if (!($this->bitmap & NET_SSH1_MASK_LOGIN)) {
[1014] Fix | Delete
user_error('Operation disallowed prior to login()');
[1015] Fix | Delete
return false;
[1016] Fix | Delete
}
[1017] Fix | Delete
[1018] Fix | Delete
if (!($this->bitmap & NET_SSH1_MASK_SHELL) && !$this->_initShell()) {
[1019] Fix | Delete
user_error('Unable to initiate an interactive shell session');
[1020] Fix | Delete
return false;
[1021] Fix | Delete
}
[1022] Fix | Delete
[1023] Fix | Delete
$data = pack('CNa*', NET_SSH1_CMSG_STDIN_DATA, strlen($cmd), $cmd);
[1024] Fix | Delete
[1025] Fix | Delete
if (!$this->_send_binary_packet($data)) {
[1026] Fix | Delete
user_error('Error sending SSH_CMSG_STDIN');
[1027] Fix | Delete
return false;
[1028] Fix | Delete
}
[1029] Fix | Delete
[1030] Fix | Delete
return true;
[1031] Fix | Delete
}
[1032] Fix | Delete
[1033] Fix | Delete
/**
[1034] Fix | Delete
* Returns the output of an interactive shell when no more output is available.
[1035] Fix | Delete
*
[1036] Fix | Delete
* Requires PHP 4.3.0 or later due to the use of the stream_select() function. If you see stuff like
[1037] Fix | Delete
* "^[[00m", you're seeing ANSI escape codes. According to
[1038] Fix | Delete
* {@link http://support.microsoft.com/kb/101875 How to Enable ANSI.SYS in a Command Window}, "Windows NT
[1039] Fix | Delete
* does not support ANSI escape sequences in Win32 Console applications", so if you're a Windows user,
[1040] Fix | Delete
* there's not going to be much recourse.
[1041] Fix | Delete
*
[1042] Fix | Delete
* @see self::interactiveRead()
[1043] Fix | Delete
* @return string
[1044] Fix | Delete
* @access public
[1045] Fix | Delete
*/
[1046] Fix | Delete
function interactiveRead()
[1047] Fix | Delete
{
[1048] Fix | Delete
if (!($this->bitmap & NET_SSH1_MASK_LOGIN)) {
[1049] Fix | Delete
user_error('Operation disallowed prior to login()');
[1050] Fix | Delete
return false;
[1051] Fix | Delete
}
[1052] Fix | Delete
[1053] Fix | Delete
if (!($this->bitmap & NET_SSH1_MASK_SHELL) && !$this->_initShell()) {
[1054] Fix | Delete
user_error('Unable to initiate an interactive shell session');
[1055] Fix | Delete
return false;
[1056] Fix | Delete
}
[1057] Fix | Delete
[1058] Fix | Delete
$read = array($this->fsock);
[1059] Fix | Delete
$write = $except = null;
[1060] Fix | Delete
if (stream_select($read, $write, $except, 0)) {
[1061] Fix | Delete
$response = $this->_get_binary_packet();
[1062] Fix | Delete
return substr($response[NET_SSH1_RESPONSE_DATA], 4);
[1063] Fix | Delete
} else {
[1064] Fix | Delete
return '';
[1065] Fix | Delete
}
[1066] Fix | Delete
}
[1067] Fix | Delete
[1068] Fix | Delete
/**
[1069] Fix | Delete
* Disconnect
[1070] Fix | Delete
*
[1071] Fix | Delete
* @access public
[1072] Fix | Delete
*/
[1073] Fix | Delete
function disconnect()
[1074] Fix | Delete
{
[1075] Fix | Delete
$this->_disconnect();
[1076] Fix | Delete
}
[1077] Fix | Delete
[1078] Fix | Delete
/**
[1079] Fix | Delete
* Destructor.
[1080] Fix | Delete
*
[1081] Fix | Delete
* Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call
[1082] Fix | Delete
* disconnect().
[1083] Fix | Delete
*
[1084] Fix | Delete
* @access public
[1085] Fix | Delete
*/
[1086] Fix | Delete
function __destruct()
[1087] Fix | Delete
{
[1088] Fix | Delete
$this->_disconnect();
[1089] Fix | Delete
}
[1090] Fix | Delete
[1091] Fix | Delete
/**
[1092] Fix | Delete
* Disconnect
[1093] Fix | Delete
*
[1094] Fix | Delete
* @param string $msg
[1095] Fix | Delete
* @access private
[1096] Fix | Delete
*/
[1097] Fix | Delete
function _disconnect($msg = 'Client Quit')
[1098] Fix | Delete
{
[1099] Fix | Delete
if ($this->bitmap) {
[1100] Fix | Delete
$data = pack('C', NET_SSH1_CMSG_EOF);
[1101] Fix | Delete
$this->_send_binary_packet($data);
[1102] Fix | Delete
/*
[1103] Fix | Delete
$response = $this->_get_binary_packet();
[1104] Fix | Delete
if ($response === true) {
[1105] Fix | Delete
$response = array(NET_SSH1_RESPONSE_TYPE => -1);
[1106] Fix | Delete
}
[1107] Fix | Delete
switch ($response[NET_SSH1_RESPONSE_TYPE]) {
[1108] Fix | Delete
case NET_SSH1_SMSG_EXITSTATUS:
[1109] Fix | Delete
$data = pack('C', NET_SSH1_CMSG_EXIT_CONFIRMATION);
[1110] Fix | Delete
break;
[1111] Fix | Delete
default:
[1112] Fix | Delete
$data = pack('CNa*', NET_SSH1_MSG_DISCONNECT, strlen($msg), $msg);
[1113] Fix | Delete
}
[1114] Fix | Delete
*/
[1115] Fix | Delete
$data = pack('CNa*', NET_SSH1_MSG_DISCONNECT, strlen($msg), $msg);
[1116] Fix | Delete
[1117] Fix | Delete
$this->_send_binary_packet($data);
[1118] Fix | Delete
fclose($this->fsock);
[1119] Fix | Delete
$this->bitmap = 0;
[1120] Fix | Delete
}
[1121] Fix | Delete
}
[1122] Fix | Delete
[1123] Fix | Delete
/**
[1124] Fix | Delete
* Gets Binary Packets
[1125] Fix | Delete
*
[1126] Fix | Delete
* See 'The Binary Packet Protocol' of protocol-1.5.txt for more info.
[1127] Fix | Delete
*
[1128] Fix | Delete
* Also, this function could be improved upon by adding detection for the following exploit:
[1129] Fix | Delete
* http://www.securiteam.com/securitynews/5LP042K3FY.html
[1130] Fix | Delete
*
[1131] Fix | Delete
* @see self::_send_binary_packet()
[1132] Fix | Delete
* @return array
[1133] Fix | Delete
* @access private
[1134] Fix | Delete
*/
[1135] Fix | Delete
function _get_binary_packet()
[1136] Fix | Delete
{
[1137] Fix | Delete
if (feof($this->fsock)) {
[1138] Fix | Delete
//user_error('connection closed prematurely');
[1139] Fix | Delete
return false;
[1140] Fix | Delete
}
[1141] Fix | Delete
[1142] Fix | Delete
if ($this->curTimeout) {
[1143] Fix | Delete
$read = array($this->fsock);
[1144] Fix | Delete
$write = $except = null;
[1145] Fix | Delete
[1146] Fix | Delete
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
[1147] Fix | Delete
$sec = floor($this->curTimeout);
[1148] Fix | Delete
$usec = 1000000 * ($this->curTimeout - $sec);
[1149] Fix | Delete
// on windows this returns a "Warning: Invalid CRT parameters detected" error
[1150] Fix | Delete
if (!@stream_select($read, $write, $except, $sec, $usec) && !count($read)) {
[1151] Fix | Delete
//$this->_disconnect('Timeout');
[1152] Fix | Delete
return true;
[1153] Fix | Delete
}
[1154] Fix | Delete
$elapsed = strtok(microtime(), ' ') + strtok('') - $start;
[1155] Fix | Delete
$this->curTimeout-= $elapsed;
[1156] Fix | Delete
}
[1157] Fix | Delete
[1158] Fix | Delete
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
[1159] Fix | Delete
$data = fread($this->fsock, 4);
[1160] Fix | Delete
if (strlen($data) < 4) {
[1161] Fix | Delete
return false;
[1162] Fix | Delete
}
[1163] Fix | Delete
$temp = unpack('Nlength', $data);
[1164] Fix | Delete
[1165] Fix | Delete
$padding_length = 8 - ($temp['length'] & 7);
[1166] Fix | Delete
$length = $temp['length'] + $padding_length;
[1167] Fix | Delete
$raw = '';
[1168] Fix | Delete
[1169] Fix | Delete
while ($length > 0) {
[1170] Fix | Delete
$temp = fread($this->fsock, $length);
[1171] Fix | Delete
if (strlen($temp) != $length) {
[1172] Fix | Delete
return false;
[1173] Fix | Delete
}
[1174] Fix | Delete
$raw.= $temp;
[1175] Fix | Delete
$length-= strlen($temp);
[1176] Fix | Delete
}
[1177] Fix | Delete
$stop = strtok(microtime(), ' ') + strtok('');
[1178] Fix | Delete
[1179] Fix | Delete
if (strlen($raw) && $this->crypto !== false) {
[1180] Fix | Delete
$raw = $this->crypto->decrypt($raw);
[1181] Fix | Delete
}
[1182] Fix | Delete
[1183] Fix | Delete
$padding = substr($raw, 0, $padding_length);
[1184] Fix | Delete
$type = $raw[$padding_length];
[1185] Fix | Delete
$data = substr($raw, $padding_length + 1, -4);
[1186] Fix | Delete
[1187] Fix | Delete
if (strlen($raw) < 4) {
[1188] Fix | Delete
return false;
[1189] Fix | Delete
}
[1190] Fix | Delete
$temp = unpack('Ncrc', substr($raw, -4));
[1191] Fix | Delete
[1192] Fix | Delete
//if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) {
[1193] Fix | Delete
// user_error('Bad CRC in packet from server');
[1194] Fix | Delete
// return false;
[1195] Fix | Delete
//}
[1196] Fix | Delete
[1197] Fix | Delete
$type = ord($type);
[1198] Fix | Delete
[1199] Fix | Delete
if (defined('NET_SSH1_LOGGING')) {
[1200] Fix | Delete
$temp = isset($this->protocol_flags[$type]) ? $this->protocol_flags[$type] : 'UNKNOWN';
[1201] Fix | Delete
$temp = '<- ' . $temp .
[1202] Fix | Delete
' (' . round($stop - $start, 4) . 's)';
[1203] Fix | Delete
$this->_append_log($temp, $data);
[1204] Fix | Delete
}
[1205] Fix | Delete
[1206] Fix | Delete
return array(
[1207] Fix | Delete
NET_SSH1_RESPONSE_TYPE => $type,
[1208] Fix | Delete
NET_SSH1_RESPONSE_DATA => $data
[1209] Fix | Delete
);
[1210] Fix | Delete
}
[1211] Fix | Delete
[1212] Fix | Delete
/**
[1213] Fix | Delete
* Sends Binary Packets
[1214] Fix | Delete
*
[1215] Fix | Delete
* Returns true on success, false on failure.
[1216] Fix | Delete
*
[1217] Fix | Delete
* @see self::_get_binary_packet()
[1218] Fix | Delete
* @param string $data
[1219] Fix | Delete
* @return bool
[1220] Fix | Delete
* @access private
[1221] Fix | Delete
*/
[1222] Fix | Delete
function _send_binary_packet($data)
[1223] Fix | Delete
{
[1224] Fix | Delete
if (feof($this->fsock)) {
[1225] Fix | Delete
//user_error('connection closed prematurely');
[1226] Fix | Delete
return false;
[1227] Fix | Delete
}
[1228] Fix | Delete
[1229] Fix | Delete
$length = strlen($data) + 4;
[1230] Fix | Delete
[1231] Fix | Delete
$padding = crypt_random_string(8 - ($length & 7));
[1232] Fix | Delete
[1233] Fix | Delete
$orig = $data;
[1234] Fix | Delete
$data = $padding . $data;
[1235] Fix | Delete
$data.= pack('N', $this->_crc($data));
[1236] Fix | Delete
[1237] Fix | Delete
if ($this->crypto !== false) {
[1238] Fix | Delete
$data = $this->crypto->encrypt($data);
[1239] Fix | Delete
}
[1240] Fix | Delete
[1241] Fix | Delete
$packet = pack('Na*', $length, $data);
[1242] Fix | Delete
[1243] Fix | Delete
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
[1244] Fix | Delete
$result = strlen($packet) == fputs($this->fsock, $packet);
[1245] Fix | Delete
$stop = strtok(microtime(), ' ') + strtok('');
[1246] Fix | Delete
[1247] Fix | Delete
if (defined('NET_SSH1_LOGGING')) {
[1248] Fix | Delete
$temp = isset($this->protocol_flags[ord($orig[0])]) ? $this->protocol_flags[ord($orig[0])] : 'UNKNOWN';
[1249] Fix | Delete
$temp = '-> ' . $temp .
[1250] Fix | Delete
' (' . round($stop - $start, 4) . 's)';
[1251] Fix | Delete
$this->_append_log($temp, $orig);
[1252] Fix | Delete
}
[1253] Fix | Delete
[1254] Fix | Delete
return $result;
[1255] Fix | Delete
}
[1256] Fix | Delete
[1257] Fix | Delete
/**
[1258] Fix | Delete
* Cyclic Redundancy Check (CRC)
[1259] Fix | Delete
*
[1260] Fix | Delete
* PHP's crc32 function is implemented slightly differently than the one that SSH v1 uses, so
[1261] Fix | Delete
* we've reimplemented it. A more detailed discussion of the differences can be found after
[1262] Fix | Delete
* $crc_lookup_table's initialization.
[1263] Fix | Delete
*
[1264] Fix | Delete
* @see self::_get_binary_packet()
[1265] Fix | Delete
* @see self::_send_binary_packet()
[1266] Fix | Delete
* @param string $data
[1267] Fix | Delete
* @return int
[1268] Fix | Delete
* @access private
[1269] Fix | Delete
*/
[1270] Fix | Delete
function _crc($data)
[1271] Fix | Delete
{
[1272] Fix | Delete
static $crc_lookup_table = array(
[1273] Fix | Delete
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
[1274] Fix | Delete
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
[1275] Fix | Delete
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
[1276] Fix | Delete
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
[1277] Fix | Delete
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
[1278] Fix | Delete
0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
[1279] Fix | Delete
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
[1280] Fix | Delete
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
[1281] Fix | Delete
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
[1282] Fix | Delete
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
[1283] Fix | Delete
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
[1284] Fix | Delete
0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
[1285] Fix | Delete
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
[1286] Fix | Delete
0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
[1287] Fix | Delete
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
[1288] Fix | Delete
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
[1289] Fix | Delete
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
[1290] Fix | Delete
0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
[1291] Fix | Delete
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
[1292] Fix | Delete
0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
[1293] Fix | Delete
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
[1294] Fix | Delete
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
[1295] Fix | Delete
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
[1296] Fix | Delete
0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
[1297] Fix | Delete
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
[1298] Fix | Delete
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
[1299] Fix | Delete
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
[1300] Fix | Delete
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
[1301] Fix | Delete
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
[1302] Fix | Delete
0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
[1303] Fix | Delete
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
[1304] Fix | Delete
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
[1305] Fix | Delete
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
[1306] Fix | Delete
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
[1307] Fix | Delete
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
[1308] Fix | Delete
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
[1309] Fix | Delete
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
[1310] Fix | Delete
0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
[1311] Fix | Delete
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
[1312] Fix | Delete
0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
[1313] Fix | Delete
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
[1314] Fix | Delete
0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
[1315] Fix | Delete
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
[1316] Fix | Delete
0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
[1317] Fix | Delete
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
[1318] Fix | Delete
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
[1319] Fix | Delete
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
[1320] Fix | Delete
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
[1321] Fix | Delete
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
[1322] Fix | Delete
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
[1323] Fix | Delete
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
[1324] Fix | Delete
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
[1325] Fix | Delete
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
[1326] Fix | Delete
0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
[1327] Fix | Delete
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
[1328] Fix | Delete
0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
[1329] Fix | Delete
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
[1330] Fix | Delete
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
[1331] Fix | Delete
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
[1332] Fix | Delete
0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
[1333] Fix | Delete
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
[1334] Fix | Delete
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
[1335] Fix | Delete
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
[1336] Fix | Delete
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
[1337] Fix | Delete
);
[1338] Fix | Delete
[1339] Fix | Delete
// For this function to yield the same output as PHP's crc32 function, $crc would have to be
[1340] Fix | Delete
// set to 0xFFFFFFFF, initially - not 0x00000000 as it currently is.
[1341] Fix | Delete
$crc = 0x00000000;
[1342] Fix | Delete
$length = strlen($data);
[1343] Fix | Delete
[1344] Fix | Delete
for ($i=0; $i<$length; $i++) {
[1345] Fix | Delete
// We AND $crc >> 8 with 0x00FFFFFF because we want the eight newly added bits to all
[1346] Fix | Delete
// be zero. PHP, unfortunately, doesn't always do this. 0x80000000 >> 8, as an example,
[1347] Fix | Delete
// yields 0xFF800000 - not 0x00800000. The following link elaborates:
[1348] Fix | Delete
// http://www.php.net/manual/en/language.operators.bitwise.php#57281
[1349] Fix | Delete
$crc = (($crc >> 8) & 0x00FFFFFF) ^ $crc_lookup_table[($crc & 0xFF) ^ ord($data[$i])];
[1350] Fix | Delete
}
[1351] Fix | Delete
[1352] Fix | Delete
// In addition to having to set $crc to 0xFFFFFFFF, initially, the return value must be XOR'd with
[1353] Fix | Delete
// 0xFFFFFFFF for this function to return the same thing that PHP's crc32 function would.
[1354] Fix | Delete
return $crc;
[1355] Fix | Delete
}
[1356] Fix | Delete
[1357] Fix | Delete
/**
[1358] Fix | Delete
* String Shift
[1359] Fix | Delete
*
[1360] Fix | Delete
* Inspired by array_shift
[1361] Fix | Delete
*
[1362] Fix | Delete
* @param string $string
[1363] Fix | Delete
* @param int $index
[1364] Fix | Delete
* @return string
[1365] Fix | Delete
* @access private
[1366] Fix | Delete
*/
[1367] Fix | Delete
function _string_shift(&$string, $index = 1)
[1368] Fix | Delete
{
[1369] Fix | Delete
$substr = substr($string, 0, $index);
[1370] Fix | Delete
$string = substr($string, $index);
[1371] Fix | Delete
return $substr;
[1372] Fix | Delete
}
[1373] Fix | Delete
[1374] Fix | Delete
/**
[1375] Fix | Delete
* RSA Encrypt
[1376] Fix | Delete
*
[1377] Fix | Delete
* Returns mod(pow($m, $e), $n), where $n should be the product of two (large) primes $p and $q and where $e
[1378] Fix | Delete
* should be a number with the property that gcd($e, ($p - 1) * ($q - 1)) == 1. Could just make anything that
[1379] Fix | Delete
* calls this call modexp, instead, but I think this makes things clearer, maybe...
[1380] Fix | Delete
*
[1381] Fix | Delete
* @see self::Net_SSH1()
[1382] Fix | Delete
* @param Math_BigInteger $m
[1383] Fix | Delete
* @param array $key
[1384] Fix | Delete
* @return Math_BigInteger
[1385] Fix | Delete
* @access private
[1386] Fix | Delete
*/
[1387] Fix | Delete
function _rsa_crypt($m, $key)
[1388] Fix | Delete
{
[1389] Fix | Delete
/*
[1390] Fix | Delete
if (!class_exists('Crypt_RSA')) {
[1391] Fix | Delete
include_once 'Crypt/RSA.php';
[1392] Fix | Delete
}
[1393] Fix | Delete
[1394] Fix | Delete
$rsa = new Crypt_RSA();
[1395] Fix | Delete
$rsa->loadKey($key, CRYPT_RSA_PUBLIC_FORMAT_RAW);
[1396] Fix | Delete
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
[1397] Fix | Delete
return $rsa->encrypt($m);
[1398] Fix | Delete
*/
[1399] Fix | Delete
[1400] Fix | Delete
// To quote from protocol-1.5.txt:
[1401] Fix | Delete
// The most significant byte (which is only partial as the value must be
[1402] Fix | Delete
// less than the public modulus, which is never a power of two) is zero.
[1403] Fix | Delete
//
[1404] Fix | Delete
// The next byte contains the value 2 (which stands for public-key
[1405] Fix | Delete
// encrypted data in the PKCS standard [PKCS#1]). Then, there are non-
[1406] Fix | Delete
// zero random bytes to fill any unused space, a zero byte, and the data
[1407] Fix | Delete
// to be encrypted in the least significant bytes, the last byte of the
[1408] Fix | Delete
// data in the least significant byte.
[1409] Fix | Delete
[1410] Fix | Delete
// Presumably the part of PKCS#1 they're refering to is "Section 7.2.1 Encryption Operation",
[1411] Fix | Delete
// under "7.2 RSAES-PKCS1-v1.5" and "7 Encryption schemes" of the following URL:
[1412] Fix | Delete
// ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf
[1413] Fix | Delete
$modulus = $key[1]->toBytes();
[1414] Fix | Delete
$length = strlen($modulus) - strlen($m) - 3;
[1415] Fix | Delete
$random = '';
[1416] Fix | Delete
while (strlen($random) != $length) {
[1417] Fix | Delete
$block = crypt_random_string($length - strlen($random));
[1418] Fix | Delete
$block = str_replace("\x00", '', $block);
[1419] Fix | Delete
$random.= $block;
[1420] Fix | Delete
}
[1421] Fix | Delete
$temp = chr(0) . chr(2) . $random . chr(0) . $m;
[1422] Fix | Delete
[1423] Fix | Delete
$m = new Math_BigInteger($temp, 256);
[1424] Fix | Delete
$m = $m->modPow($key[0], $key[1]);
[1425] Fix | Delete
[1426] Fix | Delete
return $m->toBytes();
[1427] Fix | Delete
}
[1428] Fix | Delete
[1429] Fix | Delete
/**
[1430] Fix | Delete
* Define Array
[1431] Fix | Delete
*
[1432] Fix | Delete
* Takes any number of arrays whose indices are integers and whose values are strings and defines a bunch of
[1433] Fix | Delete
* named constants from it, using the value as the name of the constant and the index as the value of the constant.
[1434] Fix | Delete
* If any of the constants that would be defined already exists, none of the constants will be defined.
[1435] Fix | Delete
*
[1436] Fix | Delete
* @access private
[1437] Fix | Delete
*/
[1438] Fix | Delete
function _define_array()
[1439] Fix | Delete
{
[1440] Fix | Delete
$args = func_get_args();
[1441] Fix | Delete
foreach ($args as $arg) {
[1442] Fix | Delete
foreach ($arg as $key => $value) {
[1443] Fix | Delete
if (!defined($value)) {
[1444] Fix | Delete
define($value, $key);
[1445] Fix | Delete
} else {
[1446] Fix | Delete
break 2;
[1447] Fix | Delete
}
[1448] Fix | Delete
}
[1449] Fix | Delete
}
[1450] Fix | Delete
}
[1451] Fix | Delete
[1452] Fix | Delete
/**
[1453] Fix | Delete
* Returns a log of the packets that have been sent and received.
[1454] Fix | Delete
*
[1455] Fix | Delete
* Returns a string if NET_SSH1_LOGGING == NET_SSH1_LOG_COMPLEX, an array if NET_SSH1_LOGGING == NET_SSH1_LOG_SIMPLE and false if !defined('NET_SSH1_LOGGING')
[1456] Fix | Delete
*
[1457] Fix | Delete
* @access public
[1458] Fix | Delete
* @return array|false|string
[1459] Fix | Delete
*/
[1460] Fix | Delete
function getLog()
[1461] Fix | Delete
{
[1462] Fix | Delete
if (!defined('NET_SSH1_LOGGING')) {
[1463] Fix | Delete
return false;
[1464] Fix | Delete
}
[1465] Fix | Delete
[1466] Fix | Delete
switch (NET_SSH1_LOGGING) {
[1467] Fix | Delete
case NET_SSH1_LOG_SIMPLE:
[1468] Fix | Delete
return $this->message_number_log;
[1469] Fix | Delete
break;
[1470] Fix | Delete
case NET_SSH1_LOG_COMPLEX:
[1471] Fix | Delete
return $this->_format_log($this->message_log, $this->protocol_flags_log);
[1472] Fix | Delete
break;
[1473] Fix | Delete
default:
[1474] Fix | Delete
return false;
[1475] Fix | Delete
}
[1476] Fix | Delete
}
[1477] Fix | Delete
[1478] Fix | Delete
/**
[1479] Fix | Delete
* Formats a log for printing
[1480] Fix | Delete
*
[1481] Fix | Delete
* @param array $message_log
[1482] Fix | Delete
* @param array $message_number_log
[1483] Fix | Delete
* @access private
[1484] Fix | Delete
* @return string
[1485] Fix | Delete
*/
[1486] Fix | Delete
function _format_log($message_log, $message_number_log)
[1487] Fix | Delete
{
[1488] Fix | Delete
$output = '';
[1489] Fix | Delete
for ($i = 0; $i < count($message_log); $i++) {
[1490] Fix | Delete
$output.= $message_number_log[$i] . "\r\n";
[1491] Fix | Delete
$current_log = $message_log[$i];
[1492] Fix | Delete
$j = 0;
[1493] Fix | Delete
do {
[1494] Fix | Delete
if (strlen($current_log)) {
[1495] Fix | Delete
$output.= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
[1496] Fix | Delete
}
[1497] Fix | Delete
$fragment = $this->_string_shift($current_log, $this->log_short_width);
[1498] Fix | Delete
$hex = substr(preg_replace_callback('#.#s', array($this, '_format_log_helper'), $fragment), strlen($this->log_boundary));
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function