Skip to content

Commit

Permalink
added iprefix, oprefix and xdialog features
Browse files Browse the repository at this point in the history
  • Loading branch information
ColumPaget committed Jan 9, 2022
1 parent b8e5d1b commit 7a6522f
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 44 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <types> Specify a list of dialog commands and use the first found on the system. Default is 'yad,zenity,qarma'.
-iprefix <prefix> String to prefix all input before hashing
-oprefix <prefix> 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> Path to an ssh private key file to use to authenticate INSTEAD OF A PASSWORD when pulling files via ssh.
Expand Down
6 changes: 4 additions & 2 deletions cgi.c
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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));
Expand Down
8 changes: 8 additions & 0 deletions command-line-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 <list>","Specify a list of dialog commands and use the first found on the system. Default is 'yad,zenity,qarma'");
printf(" %-15s %s\n","-iprefix <prefix>","String to prefix all input before hashing");
printf(" %-15s %s\n","-oprefix <prefix>","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>", "Path to an ssh private key file to use to authenticate INSTEAD OF A PASSWORD when pulling files via ssh.");
Expand Down
26 changes: 2 additions & 24 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};



Expand All @@ -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;
Expand All @@ -77,6 +53,8 @@ char *ReformatHash(char *RetStr, const char *Str, HashratCtx *Ctx)
}
}



return(RetStr);
}

Expand Down
8 changes: 1 addition & 7 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

#define IGNORE -1

#define VERSION "1.13"
#define VERSION "1.14"


typedef struct
Expand Down Expand Up @@ -131,11 +131,6 @@ ListNode *Vars;
} HashratCtx;



extern const char *LineEndingNames[];
extern const char *LineEndingDescriptions[];


extern int Flags;
extern char *DiffHook;
extern char *Key;
Expand All @@ -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
31 changes: 31 additions & 0 deletions encodings.c
Original file line number Diff line number Diff line change
@@ -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("");
}
15 changes: 15 additions & 0 deletions encodings.h
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions frontend.c
Original file line number Diff line number Diff line change
@@ -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};

15 changes: 15 additions & 0 deletions frontend.h
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions hashrat.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 <prefix>
String to prefix all input before hashing
.TP
.B
\fB-oprefix\fP <prefix>
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].
Expand Down
30 changes: 21 additions & 9 deletions xdialog.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "xdialog.h"
#include "encodings.h"
#include "frontend.h"


char *XDialogFindXDialogCommand(char *Cmd, const char *XDialogCommandList)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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))
Expand All @@ -143,16 +144,27 @@ 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);
i=MatchTokenFromList(Text, EncodingNames, 0);
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);
Expand All @@ -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))
{

Expand Down

0 comments on commit 7a6522f

Please sign in to comment.