Skip to content

Commit

Permalink
fix 'make check', compile without zlib or openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
Colum Paget committed Jun 18, 2024
1 parent 51aa10e commit d2c9eb6
Show file tree
Hide file tree
Showing 66 changed files with 3,430 additions and 2,012 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.20 (2024-06-18)
* Bring "make check" (check.sh) up to date with latest functioning of hashrat
* Compile if openssl not available (update to latest libUseful)
* Honor stdin-supplied hash type when using 'match' (-m) functionality
* Add -enable-harden, --enable-zlib and other options to ./configure

v1.19 (2024-01-15)
* Don't push comment to clipboard, just code/hash.

Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CC = gcc
CFLAGS = -g -O2
LIBS = libUseful-5/libUseful.a -lssl -lcrypto
CFLAGS = -g -O2 -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong
LIBS = libUseful-5/libUseful.a -lssl -lcrypto -lz
INSTALL=/usr/bin/install -c
prefix=/usr
prefix=/usr/local
bindir=$(prefix)${exec_prefix}/bin
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_LIBCRYPTO=1 -DHAVE_LIBSSL=1
FLAGS=$(LDFLAGS) $(CPPFLAGS) $(CFLAGS) -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DSTDC_HEADERS=1 -DHAVE_LIBZ=1 -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 otp.o memcached.o frontend.o cgi.o xdialog.o output.o
EXE=hashrat

Expand Down Expand Up @@ -74,7 +74,7 @@ check: hashrat
@./check.sh

clean:
-rm -f *.o */*.o */*.a */*.so *.orig $(EXE)
-rm -f *.o */*.o */*.a */*.so *.orig *.out $(EXE)
-rm -f config.log config.status */config.log */config.status
-rm -fr autom4te.cache */autom4te.cache

Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ check: hashrat
@./check.sh

clean:
-rm -f *.o */*.o */*.a */*.so *.orig $(EXE)
-rm -f *.o */*.o */*.a */*.so *.orig *.out $(EXE)
-rm -f config.log config.status */config.log */config.status
-rm -fr autom4te.cache */autom4te.cache

Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ OPTIONS
-period <n> Produce TOTP code with period/lifetime of <n> seconds.
-8 Encode with octal instead of hex
-10 Encode with decimal instead of hex
-H Encode with UPPERCASE hexadecimal
-HEX Encode with UPPERCASE hexadecimal
-H Encode with UPPERCASE hexadecimal instead of lowercase
-HEX Encode with UPPERCASE hexadecimal instead of lowercase
-32 Encode with base32 instead of hex
-base32 Encode with base32 instead of hex
-c32 Encode with Crockford base32 instead of hex
Expand Down Expand Up @@ -348,7 +348,6 @@ Hashrat can be used as a TOTP authenticator, and defaults to google-authenticato




HOOKSCRIPTS
===========

Expand All @@ -359,6 +358,22 @@ Hookscripts, defined using the `-h` or `-hook` command-line options, are scripts
* 'Find duplicates' mode: The hookscript is called if a file is a duplicate of another file. It is passed the paths of both files.



MATCH Mode
==========

The '-m' function allows matching a list of file hashes input on stdin. It differs from check mode in that, instead of checking a specific file against a hash supplied for the file, it accepts a hash and goes looking for any files that match that hash. However, this causes problems if different hash functions are used in the file input. Hashrat's native format allows specifying the hash-type that is supplied on a hash-by-hash basis. This works fine for 'check' mode, but in 'match' mode hashrat does not know which fingerprint/hash a file will match before it hashes it. Therefore hashrat will expect all the supplied hashes to be the same hash format when in match mode. This if suppling native-format hashes like this:

```
hash='sha1:c04b4a87e789eceb7c10c2d6a785f91820bf9db4' type='file' mode='100664' uid='1000' gid='1000' size='5759' mtime='1718700145' inode='8436275' path='tests/help.txt'
hash='md5:10fc712fd1298e2cb7a34303242d8ae4' type='file' mode='100664' uid='1000' gid='1000' size='621' mtime='1718700145' inode='8436276' path='tests/quotes.txt'
```

Hashrat will honor the LAST format given (in this case md5) and use it for matching all files.

Basically, don't mix hash types when using 'match' mode.


CGI Mode
========

Expand Down
15 changes: 7 additions & 8 deletions cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static void CGIPrintSelect(const char *Name, const char *CurrType, ListNode *Ite
Curr=ListGetNext(Items);
while(Curr)
{
if (StrValid(CurrType) && (strcmp(Curr->Tag,CurrType)==0)) printf("<option selected value=%s> %s\r\n",Curr->Tag, Curr->Item);
else printf("<option value=%s> %s\r\n",Curr->Tag, Curr->Item);
if (StrValid(CurrType) && (strcmp(Curr->Tag,CurrType)==0)) printf("<option selected value=%s> %s\r\n",Curr->Tag, (char *) Curr->Item);
else printf("<option value=%s> %s\r\n",Curr->Tag, (char *) Curr->Item);
Curr=ListGetNext(Curr);
}
printf("</select>\r\n");
Expand Down Expand Up @@ -146,7 +146,7 @@ static void CGIDrawHashResult(const char *Hash)
printf("<tr><th bgcolor=red><font color=white>Your Hash is:</font></th></tr>\r\n");
// printf("<tr><td><b>%s</b></td>\r\n",Hash);
// printf("<tr><td>Here it is in a text box so you can 'select all'</td>\r\n");
printf("<tr><td align=center><textarea align=center rows=1 cols=%d readonly style=\"font-weight: bold; font-size:16px\">%s</textarea></td>\n",StrLen(Hash)+2, Hash);
printf("<tr><td align=center><textarea align=center rows=1 cols=%lu readonly style=\"font-weight: bold; font-size:16px\">%s</textarea></td>\n",StrLen(Hash)+2, Hash);
printf("</table>\r\n");
printf("<p /><p />\r\n");
}
Expand Down Expand Up @@ -219,8 +219,7 @@ void CGIDisplayPage()
//as root, or something like that, let's try to chroot, so no weird attacks are possible

//shouldn't work, because we shouldn't be running as root
chdir("/var/empty");
chroot(".");
if (chdir("/var/empty")==0) chroot(".");

//Send HTTP Headers
printf("Content-type: text/html\r\n");
Expand Down Expand Up @@ -249,7 +248,7 @@ void CGIDisplayPage()
i=MatchTokenFromList(Encoding, EncodingNames, 0);
if (i > -1) Ctx->Encoding=Encodings[i];

if (StrLen(LineEnding))
if (StrValid(LineEnding))
{
if (strcmp(LineEnding, "crlf")==0) Text=CatStr(Text,"\r\n");
if (strcmp(LineEnding, "lf")==0) Text=CatStr(Text,"\n");
Expand All @@ -273,9 +272,9 @@ void CGIDisplayPage()
printf("<input type=hidden name=\"LineEnding\" value=\"%s\">\n",LineEnding);
printf("<input type=hidden name=\"OutputLength\" value=\"%d\">\n",OutputLength);
printf("<input type=hidden name=\"SegmentLength\" value=\"%d\">\n",SegmentLength);
if (StrLen(SegmentChar)) printf("<input type=hidden name=\"SegmentChar\" value=\"%s\">\n",SegmentChar);
if (StrValid(SegmentChar)) printf("<input type=hidden name=\"SegmentChar\" value=\"%s\">\n",SegmentChar);
printf("<input type=hidden name=\"NoOptions\" value=\"Y\">\n");
//if (StrLen(OptionsFile)) printf("<input type=hidden name=\"OptionsFile\" value=\"%d\">\n",OptionsFile);
//if (StrValid(OptionsFile)) printf("<input type=hidden name=\"OptionsFile\" value=\"%d\">\n",OptionsFile);
}
else CGIDisplayOptions(HashType, Encoding, LineEnding, OutputLength);

Expand Down
2 changes: 1 addition & 1 deletion check-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int CheckHashesFromList(HashratCtx *Ctx)
FP=FingerprintRead(ListStream);
while (FP)
{
if (StrLen(FP->HashType)) Ctx->HashType=CopyStr(Ctx->HashType, FP->HashType);
if (StrValid(FP->HashType)) Ctx->HashType=CopyStr(Ctx->HashType, FP->HashType);
if (StatFile(Ctx,FP->Path,&Stat) != -1) HashItem(Ctx, Ctx->HashType, FP->Path, &Stat, &HashStr);

if (! HashratCheckFile(Ctx, FP->Path, &Stat, HashStr, FP)) Errors++;
Expand Down
42 changes: 22 additions & 20 deletions check.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

EXIT=0

Expand Down Expand Up @@ -42,6 +42,7 @@ fi
while [ "$I" -lt "$ITER" ]
do
HR_OUT=`echo -n "The sky above the port was the color of television, tuned to a dead channel. " | ./hashrat -$1`

if [ "$HR_OUT" != "$3" ]
then
RESULT=FAIL
Expand All @@ -61,7 +62,7 @@ fi

TestLocate()
{
HR_OUT=`echo $1 | ./hashrat -m -r .`
HR_OUT=`echo $1 | ./hashrat -m -md5 -r .`

if [ "$HR_OUT" = "$2" ]
then
Expand All @@ -75,7 +76,7 @@ fi
TestLocateHook()
{
rm -f locatehook.out
HR_OUT=`echo $1 | ./hashrat -m -r . -hook "echo found > locatehook.out"`
HR_OUT=`echo $1 | ./hashrat -m -md5 -r . -hook "echo found > locatehook.out"`

if [ -e locatehook.out ]
then
Expand All @@ -98,16 +99,16 @@ FindDuplicates)
;;

HashFile)
HR_OUT=`./hashrat $2`
HR_OUT=`./hashrat -md5 $2`
EXIT_FOUND=$?
HR_OUT=`./hashrat nonexistent 2>/dev/null`
EXIT_NOTFOUND=$?
;;

*)
HR_OUT=`echo $1 $2 | ./hashrat $3 2>/dev/null`
HR_OUT=`echo $1 $2 | ./hashrat -md5 $3 2>/dev/null`
EXIT_FOUND=$?
HR_OUT=`echo $1x $2 | ./hashrat $3 2>/dev/null`
HR_OUT=`echo $1x $2 | ./hashrat -md5 $3 2>/dev/null`
EXIT_NOTFOUND=$?
;;
esac
Expand Down Expand Up @@ -149,21 +150,22 @@ TestHash whirlpool "1000 whirlpool" b690486285b18a9cbea3105a8f7e8ee439ef878530fe
TestHash jh384 "1000 jh384" 55c63e4c22303227495c076ba0b11cda09a77856b98ee7d285283509415ca47141b09136daaada9fa3f10522456484db 1000

Title "Testing Encoding"
TestHash 8 "base 8 (octal) encoding" 150350216173106240373330245114211062322251161015
TestHash 10 "base 10 (decimal) encoding" 104232142123070160251216165076137050210169113013
TestHash HEX "UPPERCASE base 16 (HEX) encoding" 68E88E7B46A0FBD8A54C8932D2A9710D
TestHash 64 "base 64 encoding" aOiOe0ag+9ilTIky0qlxDQ==
TestHash u64 "uu-encode style base 64 encoding" ":.B.>T:@^]BE3(DRTJEQ#0''"
TestHash x64 "xx-encode style base 64 encoding" "OCWCSoOUyxWZH6YmoeZl1E++"
TestHash p64 "'website compatible' base 64 encoding" "PDXDToPVyxX_I8Zmoe_l3F"
TestHash a85 "ASCII85 encoding" "B]tJ7\KYV+c_d]%3"
TestHash z85 "ZEROMQ85 encoding" "wX%ElWFTQ9+Z=X4h"
TestHash 8 "base 8 (octal) encoding" 322177026032202322203112374315246277301321013040044374156300
TestHash 10 "base 10 (decimal) encoding" 210127022026130210131074252205166191193209011032036252110192
TestHash 16 "lowercase base 16 (hex) encoding" d27f161a82d2834afccda6bfc1d10b2024fc6ec0
TestHash HEX "UPPERCASE base 16 (HEX) encoding" D27F161A82D2834AFCCDA6BFC1D10B2024FC6EC0
TestHash 32 "base 32 encoding" "2J7RMGUC2KBUV7GNU274DUILEASPY3WA========"
TestHash 64 "base 64 encoding" "0n8WGoLSg0r8zaa/wdELICT8bsA="
TestHash x64 "xx-encode style base 64 encoding" "obwK4c9GUofwnOOzkR2960HwPg++"
TestHash p64 "'website compatible' base 64 encoding" "obwL6cAHVofwnPPzkS4A82IwQg0"
TestHash a85 "ASCII85 encoding" 'dXN#K$o9r6;+_9iW,lDP'
TestHash z85 "ZEROMQ85 encoding" "=SI2F3[n}kp9Zn?Ra>yK"


Title "Testing Misc. Features"

HR_OUT=`./hashrat -version`
if [ "$HR_OUT" = "version: 1.15" ]
if [ "$HR_OUT" = "version: 1.20" ]
then
OkayMessage "Version (-version) works"
else
Expand Down Expand Up @@ -197,7 +199,7 @@ else
fi

HR_OUT=`./hashrat -trad -f tests/test.lst | ./hashrat -trad -md5`
if [ "$HR_OUT" = "85842879a67baa126b105130ed3f7683" ]
if [ "$HR_OUT" = "d6ab85e877b3bef43975a168f22be006" ]
then
OkayMessage "File hashing from a listfile works"
else
Expand All @@ -206,7 +208,7 @@ fi


HR_OUT=`cat tests/test.lst | ./hashrat -trad -f - | ./hashrat -trad -md5`
if [ "$HR_OUT" = "85842879a67baa126b105130ed3f7683" ]
if [ "$HR_OUT" = "d6ab85e877b3bef43975a168f22be006" ]
then
OkayMessage "File hashing from a list on stdin works"
else
Expand Down Expand Up @@ -248,10 +250,10 @@ TestLocateHook "hash='md5:6933ee7eb504d29312b23a47d2dac374' mode='100644' uid='0

Title "Testing exit codes for different operations"
TestExitCodes "6ec9de513a8ff1768eb4768236198cf3" "tests/help.txt" "" "HashFile"
TestExitCodes "tests" "libUseful-4" "-r -dups" "FindDuplicates"
TestExitCodes "tests" "libUseful-5" "-r -dups" "FindDuplicates"
TestExitCodes "6ec9de513a8ff1768eb4768236198cf3" "tests/help.txt" "-cf" "CheckHash"
TestExitCodes "6ec9de513a8ff1768eb4768236198cf3" "tests/help.txt" "-m -r ." "Locate"
TestExitCodes "tests" "libUseful-4" "-r -dups" "FindDuplicates"
TestExitCodes "tests" "libUseful-5" "-r -dups" "FindDuplicates"

echo
echo
Expand Down
2 changes: 1 addition & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "libUseful-5/libUseful.h"
#include "glob.h"

#define VERSION "1.19"
#define VERSION "1.20"

#define ACT_NONE 0
#define ACT_HASH 1
Expand Down
Loading

0 comments on commit d2c9eb6

Please sign in to comment.