Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp30023-2019-project-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Zhang
comp30023-2019-project-2
Commits
acdee338
Commit
acdee338
authored
May 24, 2019
by
ChouTatsumi
Browse files
Options
Downloads
Patches
Plain Diff
test for pwd4
parent
d44c3eb7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
crack.c
+151
-29
151 additions, 29 deletions
crack.c
with
151 additions
and
29 deletions
crack.c
+
151
−
29
View file @
acdee338
...
@@ -6,58 +6,153 @@
...
@@ -6,58 +6,153 @@
#include
"sha256.h"
#include
"sha256.h"
// constants
// constants
#define BUFFERSIZE 256
#define PWD4_FILENAME "pwd4sha256"
#define PWD4_FILENAME "pwd4sha256"
#define PWD6_FILENAME "pwd6sha256"
#define PWD6_FILENAME "pwd6sha256"
#define PWD4_NUMBERS 10
#define PWD_NUMBERS 30
#define PWD_NUMBERS 30
#define BUFFERSIZE 256
#define ASCII_FROM 32
#define ASCII_TO 126
#define ASCII_NUM_FROM 48
#define ASCII_NUM_TO 57
#define ASCII_UPPERCASE_FROM 65
#define ASCII_UPPERCASE_TO 90
#define ASCII_LOWERCASE_FROM 97
#define ASCII_LOWERCASE_TO 122
// methods reference
// methods reference
void
check_guess
(
BYTE
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
]);
void
check_guess
(
BYTE
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
],
int
checked
[]);
void
check_n_guess
(
BYTE
guess
[],
BYTE
pwd
[][
SHA256_BLOCK_SIZE
],
int
n
,
int
checked
[]);
void
int_array_init
(
int
array
[],
int
n
);
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
==
1
)
{
if
(
argc
==
1
)
{
// record 30 passwords
// store 30 passwords to guess
FILE
*
pwdfp
;
FILE
*
fp
;
unsigned
char
buffer
[
SHA256_BLOCK_SIZE
];
BYTE
buffer
[
SHA256_BLOCK_SIZE
];
// create array to store hashes password
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
];
int
status
;
int
status
;
pwd
fp
=
fopen
(
PWD4_FILENAME
,
"rb"
);
fp
=
fopen
(
PWD4_FILENAME
,
"rb"
);
int
i
;
for
(
i
=
0
;
i
<
PWD4_NUMBERS
;
i
++
)
{
// read 32 bytes to buffer
// read 32 bytes to buffer
status
=
fread
(
buffer
,
SHA256_BLOCK_SIZE
,
1
,
pwd
fp
);
status
=
fread
(
buffer
,
SHA256_BLOCK_SIZE
,
1
,
fp
);
if
(
status
<
0
)
{
if
(
status
<
0
)
{
fprintf
(
stderr
,
"ERROR reading binary file
\n
"
);
fprintf
(
stderr
,
"ERROR
,
reading binary file
failed
\n
"
);
exit
(
0
);
exit
(
0
);
}
}
printf
(
"%u
\n
"
,
buffer
);
strcpy
((
char
*
)
&
pwd
[
i
],
(
char
*
)
&
buffer
);
}
fclose
(
fp
);
f
close
(
pwdfp
);
f
p
=
fopen
(
PWD6_FILENAME
,
"rb"
);
}
else
if
(
argc
==
2
)
{
for
(;
i
<
PWD_NUMBERS
;
i
++
)
{
// read 32 bytes to buffer
status
=
fread
(
buffer
,
SHA256_BLOCK_SIZE
,
1
,
fp
);
if
(
status
<
0
)
{
fprintf
(
stderr
,
"ERROR, reading binary file failed
\n
"
);
exit
(
0
);
}
strcpy
((
char
*
)
&
pwd
[
i
],
(
char
*
)
&
buffer
);
}
fclose
(
fp
);
// create guess and check it
// crazy test
BYTE
guess
[
5
]
=
{
"aaaa"
};
// guess[4] = '\0';
int
checked
[
10
];
int_array_init
(
checked
,
10
);
check_n_guess
(
guess
,
pwd
,
10
,
checked
);
// int first, second, third, fourth;
// for (first = ASCII_FROM; first <= ASCII_TO; first++) {
// guess[0] = first;
// for (second = ASCII_FROM; second <= ASCII_TO; second++) {
// guess[1] = second;
// for (third = ASCII_FROM; third <= ASCII_TO; third++) {
// guess[2] = third;
// for (fourth = ASCII_FROM; fourth <= ASCII_TO; fourth++) {
// guess[3] = fourth;
// check_n_guess(guess, pwd, 10, checked);
// }
// }
// }
// }
}
else
if
(
argc
==
2
)
{
// This part for good guess
}
else
if
(
argc
==
3
)
{
}
else
if
(
argc
==
3
)
{
FILE
*
guessfp
;
FILE
*
fp
;
FILE
*
pwdfp
;
BYTE
buffer
[
BUFFERSIZE
];
char
buffer
[
BUFFERSIZE
];
// read password file and store hashes passwords
fp
=
fopen
(
argv
[
2
],
"rb"
);
int
status
;
// get the number of input passwords
int
pwdcount
=
0
,
pwdsize
=
0
;
fseek
(
fp
,
0
,
SEEK_END
);
pwdsize
=
ftell
(
fp
);
pwdcount
=
pwdsize
/
SHA256_BLOCK_SIZE
;
if
(
pwdsize
%
SHA256_BLOCK_SIZE
)
{
fprintf
(
stderr
,
"ERROR, undefined password input file size
\n
"
);
exit
(
0
);
}
// create array to store hashes passwords
BYTE
pwd
[
pwdcount
][
SHA256_BLOCK_SIZE
];
int
i
;
for
(
i
=
0
;
i
<
pwdcount
;
i
++
)
{
// read 32 bytes to buffer
status
=
fread
(
buffer
,
SHA256_BLOCK_SIZE
,
1
,
fp
);
guessfp
=
fopen
(
argv
[
1
],
"r"
);
if
(
status
<
0
)
{
pwdfp
=
fopen
(
argv
[
2
],
"rb"
);
fprintf
(
stderr
,
"ERROR, reading binary file failed
\n
"
);
exit
(
0
);
}
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
guessfp
)
!=
NULL
)
{
strcpy
((
char
*
)
&
pwd
[
i
],
(
char
*
)
&
buffer
);
printf
(
"%s"
,
buffer
);
}
}
fclose
(
fp
);
fclose
(
guessfp
);
// read guess from file and check guess
fclose
(
pwdfp
);
fp
=
fopen
(
argv
[
1
],
"r"
);
// create flag arrays to avoid repeat check
int
checked
[
pwdcount
];
int_array_init
(
checked
,
pwdcount
);
while
(
fgets
((
char
*
)
&
buffer
,
BUFFERSIZE
,
fp
)
!=
NULL
)
{
// get rid of \n for buffer
buffer
[
strlen
((
char
*
)
&
buffer
)
-
1
]
=
'\0'
;
check_n_guess
(
buffer
,
pwd
,
pwdcount
,
checked
);
}
fclose
(
fp
);
}
}
return
0
;
return
0
;
}
}
void
check_guess
(
BYTE
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
])
{
void
check_guess
(
BYTE
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
],
int
checked
[])
{
SHA256_CTX
ctx
;
SHA256_CTX
ctx
;
BYTE
buf
[
SHA256_BLOCK_SIZE
];
BYTE
buf
[
SHA256_BLOCK_SIZE
];
size_t
guess_len
=
strlen
((
char
*
)
&
guess
);
size_t
guess_len
=
strlen
((
char
*
)
&
guess
);
...
@@ -68,14 +163,16 @@ void check_guess(BYTE guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE]) {
...
@@ -68,14 +163,16 @@ void check_guess(BYTE guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE]) {
sha256_final
(
&
ctx
,
buf
);
sha256_final
(
&
ctx
,
buf
);
if
(
guess_len
==
4
)
{
if
(
guess_len
==
4
)
{
for
(
i
=
0
;
i
<
10
;
i
++
)
{
for
(
i
=
0
;
i
<
PWD4_NUMBERS
;
i
++
)
{
if
(
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
if
(
!
checked
[
i
]
&&
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
checked
[
i
]
=
1
;
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
}
}
}
}
}
else
if
(
guess_len
==
6
)
{
}
else
if
(
guess_len
==
6
)
{
for
(
i
=
10
;
i
<
30
;
i
++
)
{
for
(
i
=
PWD4_NUMBERS
;
i
<
PWD_NUMBERS
;
i
++
)
{
if
(
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
if
(
!
checked
[
i
]
&&
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
checked
[
i
]
=
1
;
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
}
}
}
}
...
@@ -84,3 +181,28 @@ void check_guess(BYTE guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE]) {
...
@@ -84,3 +181,28 @@ void check_guess(BYTE guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE]) {
exit
(
0
);
exit
(
0
);
}
}
}
}
void
check_n_guess
(
BYTE
guess
[],
BYTE
pwd
[][
SHA256_BLOCK_SIZE
],
int
n
,
int
checked
[])
{
SHA256_CTX
ctx
;
BYTE
buf
[
SHA256_BLOCK_SIZE
];
size_t
guess_len
=
strlen
((
char
*
)
&
guess
);
int
i
;
sha256_init
(
&
ctx
);
sha256_update
(
&
ctx
,
guess
,
guess_len
);
sha256_final
(
&
ctx
,
buf
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%d %s %s
\n
"
,
checked
[
i
],
buf
,
pwd
[
i
]);
if
(
!
checked
[
i
]
&&
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
checked
[
i
]
=
1
;
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
}
}
}
void
int_array_init
(
int
array
[],
int
n
)
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
array
[
i
]
=
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment