From 7a6522f7629782e792fd8380887c17e7795c2cf9 Mon Sep 17 00:00:00 2001 From: ColumPaget Date: Sun, 9 Jan 2022 15:56:34 +0000 Subject: [PATCH] added iprefix, oprefix and xdialog features --- Makefile | 5 ++++- Makefile.in | 5 ++++- README.md | 4 ++++ cgi.c | 6 ++++-- command-line-args.c | 8 ++++++++ common.c | 26 ++------------------------ common.h | 8 +------- encodings.c | 31 +++++++++++++++++++++++++++++++ encodings.h | 15 +++++++++++++++ frontend.c | 5 +++++ frontend.h | 15 +++++++++++++++ hashrat.1 | 16 ++++++++++++++++ xdialog.c | 30 +++++++++++++++++++++--------- 13 files changed, 130 insertions(+), 44 deletions(-) create mode 100644 encodings.c create mode 100644 encodings.h create mode 100644 frontend.c create mode 100644 frontend.h diff --git a/Makefile b/Makefile index de10fca..d4008ec 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ INSTALL=/bin/install -c prefix=/usr/local bindir=$(prefix)${exec_prefix}/bin FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBCRYPTO=1 -DHAVE_LIBSSL=1 -OBJ=common.o encodings.o command-line-args.o ssh.o http.o fingerprint.o include-exclude.o files.o filesigning.o xattr.o check-hash.o find.o memcached.o cgi.o xdialog.o +OBJ=common.o encodings.o command-line-args.o ssh.o http.o fingerprint.o include-exclude.o files.o filesigning.o xattr.o check-hash.o find.o memcached.o frontend.o cgi.o xdialog.o EXE=hashrat all: hashrat @@ -50,6 +50,9 @@ ssh.o: ssh.h ssh.c http.o: http.h http.c $(CC) $(FLAGS) -c http.c +frontend.o: frontend.h frontend.c + $(CC) $(FLAGS) -c frontend.c + cgi.o: cgi.h cgi.c $(CC) $(FLAGS) -c cgi.c diff --git a/Makefile.in b/Makefile.in index 78d7288..d2a0884 100644 --- a/Makefile.in +++ b/Makefile.in @@ -6,7 +6,7 @@ INSTALL=@INSTALL@ prefix=@prefix@ bindir=$(prefix)@bindir@ FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) @DEFS@ -OBJ=common.o encodings.o command-line-args.o ssh.o http.o fingerprint.o include-exclude.o files.o filesigning.o xattr.o check-hash.o find.o memcached.o cgi.o xdialog.o +OBJ=common.o encodings.o command-line-args.o ssh.o http.o fingerprint.o include-exclude.o files.o filesigning.o xattr.o check-hash.o find.o memcached.o frontend.o cgi.o xdialog.o EXE=hashrat all: hashrat @@ -50,6 +50,9 @@ ssh.o: ssh.h ssh.c http.o: http.h http.c $(CC) $(FLAGS) -c http.c +frontend.o: frontend.h frontend.c + $(CC) $(FLAGS) -c frontend.c + cgi.o: cgi.h cgi.c $(CC) $(FLAGS) -c cgi.c diff --git a/README.md b/README.md index 86fff11..375f6ab 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,10 @@ OPTIONS -rawlines Read lines from stdin and hash each line independantly, INCLUDING any trailing whitespace. (This is compatible with 'echo text | md5sum') -rl Read lines from stdin and hash each line independantly, INCLUDING any trailing whitespace. (This is compatible with 'echo text | md5sum') -cgi Run in HTTP CGI mode + -xdialog Run in 'xdialog' (zenity, yad or qarama) mode. + -dialog-types Specify a list of dialog commands and use the first found on the system. Default is 'yad,zenity,qarma'. + -iprefix String to prefix all input before hashing + -oprefix Prefix to add to the front of output hashes -net Treat 'file' arguments as either ssh or http URLs, and pull files over the network and then hash them (Allows hashing of files on remote machines). URLs are in the format ssh://[username]:[password]@[host]:[port] or http://[username]:[password]@[host]:[port].. -idfile Path to an ssh private key file to use to authenticate INSTEAD OF A PASSWORD when pulling files via ssh. diff --git a/cgi.c b/cgi.c index 7b370e0..d55f51b 100644 --- a/cgi.c +++ b/cgi.c @@ -1,6 +1,6 @@ #include "cgi.h" #include "files.h" -#include "encodings.h" +#include "frontend.h" //This file provides an HTTP Common Gateway Interface for Hashrat @@ -251,7 +251,9 @@ void CGIDisplayPage() if (StrLen(LineEnding)) { - Text=PreProcessInput(Text, ptr, GetVar(Ctx->Vars,"InputPrefix"), LineEnding); + if (strcmp(LineEnding, "crlf")==0) Text=CatStr(Text,"\r\n"); + if (strcmp(LineEnding, "lf")==0) Text=CatStr(Text,"\n"); + if (strcmp(LineEnding, "cr")==0) Text=CatStr(Text,"\r"); } ProcessData(&Hash, Ctx, Text, StrLen(Text)); diff --git a/command-line-args.c b/command-line-args.c index 5839c95..2973e09 100644 --- a/command-line-args.c +++ b/command-line-args.c @@ -146,6 +146,7 @@ HashratCtx *CommandLineParseArg0() Ctx->Vars=ListCreate(); Ctx->Out=STREAMFromFD(1); SetVar(Ctx->Vars,"HashType","md5"); + SetVar(Ctx->Vars,"DialogTypes","yad,zenity,qarma"); //argv[0] might be full path to the program, or just its name @@ -283,6 +284,8 @@ HashratCtx *CommandLineParseArgs(int argc, char *argv[]) else if (strcmp(arg,"-f")==0) CommandLineHandleArg( Ctx,FLAG_NEXTARG, "ItemsListSource", "", Ctx->Vars); else if (strcmp(arg,"-iprefix")==0) CommandLineHandleArg( Ctx, FLAG_NEXTARG, "InputPrefix", "", Ctx->Vars); else if (strcmp(arg,"-oprefix")==0) CommandLineHandleArg( Ctx, FLAG_NEXTARG, "OutputPrefix", "", Ctx->Vars); + else if (strcmp(arg,"-dialog-type")==0) CommandLineHandleArg(Ctx, FLAG_NEXTARG, "DialogTypes", "",Ctx->Vars); + else if (strcmp(arg,"-dialog-types")==0) CommandLineHandleArg(Ctx, FLAG_NEXTARG, "DialogTypes", "",Ctx->Vars); else if (strcmp(arg,"-i")==0) CommandLineSetCtx(Ctx, CTX_INCLUDE,0); else if (strcmp(arg,"-name")==0) CommandLineSetCtx(Ctx, CTX_INCLUDE,0); else if (strcmp(arg,"-mtime")==0) CommandLineSetCtx(Ctx, CTX_MTIME,0); @@ -492,6 +495,11 @@ void CommandLinePrintUsage() printf(" %-15s %s\n","-rawlines", "Read lines from stdin and hash each line independantly, INCLUDING any trailing whitespace. (This is compatible with 'echo text | md5sum')"); printf(" %-15s %s\n","-rl", "Read lines from stdin and hash each line independantly, INCLUDING any trailing whitespace. (This is compatible with 'echo text | md5sum')"); printf(" %-15s %s\n","-cgi", "Run in HTTP CGI mode"); + printf(" %-15s %s\n","-cgi", "Run in HTTP CGI mode"); + printf(" %-15s %s\n","-xdialog","Run in 'xdialog' (zenity, yad or qarama) mode"); + printf(" %-15s %s\n","-dialog-types ","Specify a list of dialog commands and use the first found on the system. Default is 'yad,zenity,qarma'"); + printf(" %-15s %s\n","-iprefix ","String to prefix all input before hashing"); + printf(" %-15s %s\n","-oprefix ","Prefix to add to the front of output hashes"); printf(" %-15s %s\n","-net", "Treat 'file' arguments as either ssh or http URLs, and pull files over the network and then hash them (Allows hashing of files on remote machines)."); printf(" %-15s %s\n","", "URLs are in the format ssh://[username]:[password]@[host]:[port] or http://[username]:[password]@[host]:[port].."); printf(" %-15s %s\n","-idfile ", "Path to an ssh private key file to use to authenticate INSTEAD OF A PASSWORD when pulling files via ssh."); diff --git a/common.c b/common.c index 01ef8eb..c2adf1a 100644 --- a/common.c +++ b/common.c @@ -13,9 +13,6 @@ uint64_t HashStartTime; const char *HashratHashTypes[]= {"md5","sha1","sha256","sha512","whirl","whirlpool","jh-224","jh-256","jh-384","jh-512",NULL}; -const char *LineEndingNames[]= {"none","lf","crlf","cr",NULL}; -const char *LineEndingDescriptions[]= {"None","Unix newline","DOS carriage-return and newline","carriage-return",NULL}; -typedef enum {LINEEND_NONE, LINEEND_LF, LINEEND_CRLF, LINEEND_CR}; @@ -33,27 +30,6 @@ void HashratCtxDestroy(void *p_Ctx) } - -char *PreProcessInput(char *RetStr, const char *Text, const char *Prefix, const char *LineEnding) -{ -int i; - - RetStr=MCopyStr(RetStr, Prefix, Text, NULL); - - i=MatchTokenFromList(LineEnding, LineEndingDescriptions, 0); - if (i == -1) i=MatchTokenFromList(LineEnding, LineEndingNames, 0); - - switch (i) - { - case LINEEND_CRLF: RetStr=CatStr(RetStr,"\r\n"); break; - case LINEEND_LF: RetStr=CatStr(RetStr,"\n"); break; - case LINEEND_CR: RetStr=CatStr(RetStr,"\r"); break; - } - -return(RetStr); -} - - char *ReformatHash(char *RetStr, const char *Str, HashratCtx *Ctx) { int ipos=0, opos=0; @@ -77,6 +53,8 @@ char *ReformatHash(char *RetStr, const char *Str, HashratCtx *Ctx) } } + + return(RetStr); } diff --git a/common.h b/common.h index 5c350ee..38b60fa 100644 --- a/common.h +++ b/common.h @@ -96,7 +96,7 @@ #define IGNORE -1 -#define VERSION "1.13" +#define VERSION "1.14" typedef struct @@ -131,11 +131,6 @@ ListNode *Vars; } HashratCtx; - -extern const char *LineEndingNames[]; -extern const char *LineEndingDescriptions[]; - - extern int Flags; extern char *DiffHook; extern char *Key; @@ -152,6 +147,5 @@ void HashratStoreHash(HashratCtx *Ctx, const char *Path, struct stat *Stat, cons int HashratOutputInfo(HashratCtx *Ctx, STREAM *S, const char *Path, struct stat *Stat, const char *Hash); void RunHookScript(const char *Hook, const char *Path, const char *Other); char *ReformatHash(char *RetStr, const char *Str, HashratCtx *Ctx); -char *PreProcessInput(char *RetStr, const char *Text, const char *Prefix, const char *LineEnding); #endif diff --git a/encodings.c b/encodings.c new file mode 100644 index 0000000..6f46e77 --- /dev/null +++ b/encodings.c @@ -0,0 +1,31 @@ +#include "encodings.h" + +const char *EncodingNames[]= {"octal","dec","hex","uhex","base64","ibase64","pbase64","xxencode","uuencode","crypt","ascii85","z85",NULL}; +const char *EncodingDescriptions[]= {"Octal","Decimal","Hexadecimal","Uppercase Hexadecimal","Base64","IBase64","PBase64","XXEncode","UUEncode","Crypt","ASCII85","Z85",NULL}; +int Encodings[]= {ENCODE_OCTAL, ENCODE_DECIMAL, ENCODE_HEX, ENCODE_HEXUPPER, ENCODE_BASE64, ENCODE_IBASE64, ENCODE_PBASE64, ENCODE_XXENC, ENCODE_UUENC, ENCODE_CRYPT, ENCODE_ASCII85, ENCODE_Z85, -1}; + + +char *EncodingNameFromID(int id) +{ + int i; + + for (i=0; Encodings[i] != -1; i++) + { + if (Encodings[i]==id) return(EncodingNames[i]); + } + + return(""); +} + + +char *EncodingDescriptionFromID(int id) +{ + int i; + + for (i=0; Encodings[i] != -1; i++) + { + if (Encodings[i]==id) return(EncodingDescriptions[i]); + } + + return(""); +} diff --git a/encodings.h b/encodings.h new file mode 100644 index 0000000..68e3d63 --- /dev/null +++ b/encodings.h @@ -0,0 +1,15 @@ +#ifndef HASHRAT_ENCODING_H +#define HASHRAT_ENCODING_H + +#include "common.h" + +//provides certain values for use in frontends like .cgi and xdialog + +extern const char *EncodingNames[]; +extern const char *EncodingDescriptions[]; +extern int Encodings[]; + +char *EncodingNameFromID(int id); +char *EncodingDescriptionFromID(int id); + +#endif diff --git a/frontend.c b/frontend.c new file mode 100644 index 0000000..46f0567 --- /dev/null +++ b/frontend.c @@ -0,0 +1,5 @@ +#include "frontend.h" + +const char *LineEndingNames[]= {"none","lf","crlf","cr",NULL}; +const char *LineEndingDescriptions[]= {"None","Unix newline","DOS carriage-return and newline","carriage-return",NULL}; + diff --git a/frontend.h b/frontend.h new file mode 100644 index 0000000..e5a96c1 --- /dev/null +++ b/frontend.h @@ -0,0 +1,15 @@ +#ifndef HASHRAT_FRONTEND_H +#define HASHRAT_FRONTEND_H + +#include "common.h" + +//provides certain values for use in frontends like .cgi and xdialog + +extern const char *EncodingNames[]; +extern const char *EncodingDescriptions[]; +extern int Encodings[]; + +extern const char *LineEndingNames[]; +extern const char *LineEndingDescriptions[]; + +#endif diff --git a/hashrat.1 b/hashrat.1 index d37e1b7..270e3f4 100644 --- a/hashrat.1 +++ b/hashrat.1 @@ -255,6 +255,22 @@ Read lines from stdin and \fIhash\fP each line independantly, INCLUDING any trai Run in HTTP CGI mode. .TP .B +\fB-xdialog\fP +Run in 'xdialog' (zenity, yad or qarama) mode. +.TP +.B +\fB-dialog-types\fP +Specify a list of dialog commands and use the first found on the system. Default is 'yad,zenity,qarma'. +.TP +.B +\fB-iprefix\fP +String to prefix all input before hashing +.TP +.B +\fB-oprefix\fP +Prefix to add to the front of output hashes +.TP +.B \fB-net\fP Treat '\fIfile\fP' arguments as either ssh or http URLs, and pull files over the network and then \fIhash\fP them (allows hashing of files on remote machines). URLs are in the format ssh://[username]:[password]@[host]:[port] or http://[username]:[password]@[host]:[port]. diff --git a/xdialog.c b/xdialog.c index 9844384..1bd308a 100644 --- a/xdialog.c +++ b/xdialog.c @@ -1,5 +1,6 @@ #include "xdialog.h" -#include "encodings.h" +#include "frontend.h" + char *XDialogFindXDialogCommand(char *Cmd, const char *XDialogCommandList) { @@ -28,7 +29,6 @@ char *XDialogFindXDialogCommand(char *Cmd, const char *XDialogCommandList) char *XDialogFormInit(char *Cmd, const char *DialogCmd, const char *Title) { - Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --title='", Title, "'", NULL); return(Cmd); } @@ -100,6 +100,7 @@ STREAM *XDialogDisplayPage(const char *Dialog, HashratCtx *Config) Cmd=XDialogFormAddList(Cmd, Dialog, "Line Ending", Tempstr, ""); Cmd=XDialogFormAddTextEntry(Cmd, Dialog, "Input"); + printf("CMD: %s\n", Cmd); S=STREAMOpen(Cmd, "rw"); Destroy(Tempstr); @@ -108,13 +109,14 @@ STREAM *XDialogDisplayPage(const char *Dialog, HashratCtx *Config) return(S); } -void XDialogDisplayHash(const char *DialogCmd, const char *Hash, HashratCtx *Config) +void XDialogDisplayHash(const char *DialogCmd, const char *Hash) { char *Cmd=NULL, *Tempstr=NULL; STREAM *S; - Tempstr=ReformatHash(Tempstr, Hash, Config); - Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --info --title='Your Hash Value' --text='", Tempstr, "'", NULL); + + if (strcmp(GetBasename(DialogCmd), "yad")==0) Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --info --selectable-labels --title='Your Hash Value' --text='", Hash, "'", NULL); + else Cmd=MCopyStr(Cmd, "cmd:", DialogCmd, " --info --title='Your Hash Value' --text='", Hash, "'", NULL); S=STREAMOpen(Cmd, "rw"); Tempstr=STREAMReadLine(Tempstr, S); STREAMClose(S); @@ -134,7 +136,6 @@ int XDialogProcess(const char *Cmd, HashratCtx *Config) S=XDialogDisplayPage(Cmd, Config); Tempstr=STREAMReadLine(Tempstr, S); - StripCRLF(Tempstr); STREAMClose(S); if (StrValid(Tempstr)) @@ -143,6 +144,9 @@ int XDialogProcess(const char *Cmd, HashratCtx *Config) Ctx=(HashratCtx *) calloc(1,sizeof(HashratCtx)); Ctx->Encoding |=ENCODE_HEX; +// Ctx->OutputLength=OutputLength; +// Ctx->SegmentLength=SegmentLength; +// Ctx->SegmentChar=SegmentChar[0]; ptr=GetToken(Tempstr, "|", &Ctx->HashType, 0); ptr=GetToken(ptr, "|", &Text, 0); @@ -150,9 +154,17 @@ int XDialogProcess(const char *Cmd, HashratCtx *Config) if (i > -1) Ctx->Encoding=Encodings[i]; ptr=GetToken(ptr, "|", &LineEnding, 0); - Text=PreProcessInput(Text, ptr, GetVar(Ctx->Vars,"InputPrefix"), LineEnding); + if (StrLen(LineEnding)) + { + if (strcmp(LineEnding, "crlf")==0) Text=CatStr(Text,"\r\n"); + if (strcmp(LineEnding, "lf")==0) Text=CatStr(Text,"\n"); + if (strcmp(LineEnding, "cr")==0) Text=CatStr(Text,"\r"); + } + + Text=CopyStr(Text, ptr); + ProcessData(&Tempstr, Ctx, Text, StrLen(Text)); - XDialogDisplayHash(Cmd, Tempstr, Ctx); + XDialogDisplayHash(Cmd, Tempstr); } Destroy(LineEnding); @@ -167,7 +179,7 @@ void XDialogFrontend(HashratCtx *Config) { char *Cmd=NULL; - Cmd=XDialogFindXDialogCommand(Cmd, "yad,zenity,qarma"); + Cmd=XDialogFindXDialogCommand(Cmd, GetVar(Config->Vars, "DialogTypes")); while (XDialogProcess(Cmd, Config)) {