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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Zhang
comp30023-2019-project-2
Commits
e3a4e66a
Commit
e3a4e66a
authored
6 years ago
by
ChouTatsumi
Browse files
Options
Downloads
Patches
Plain Diff
complete PWD4 crack
parent
72f3b755
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
crack.c
+76
-57
76 additions, 57 deletions
crack.c
found_pwds.txt
+10
-0
10 additions, 0 deletions
found_pwds.txt
with
88 additions
and
58 deletions
.gitignore
+
2
−
1
View file @
e3a4e66a
...
...
@@ -2,3 +2,4 @@
**/test.*
**/*.exe
**/*.o
**/cheat
\ No newline at end of file
This diff is collapsed.
Click to expand it.
crack.c
+
76
−
57
View file @
e3a4e66a
...
...
@@ -6,10 +6,11 @@
#include
"sha256.h"
// constants
#define
BUFFERSIZE 256
#define
INPUTSIZE 10000
#define PWD4_FILENAME "pwd4sha256"
#define PWD6_FILENAME "pwd6sha256"
#define OUTPUT_FILENAME "found_pwds.txt"
#define PWD4_NUMBERS 10
#define PWD_NUMBERS 30
...
...
@@ -23,9 +24,9 @@
#define ASCII_LOWERCASE_TO 122
// methods reference
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
,
void
check_guess
(
char
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
],
int
checked
[]);
void
check_n_guess
(
char
guess
[],
BYTE
pwd
[][
SHA256_BLOCK_SIZE
],
int
n
,
int
checked
[]);
void
int_array_init
(
int
array
[],
int
n
);
...
...
@@ -50,7 +51,7 @@ int main(int argc, char** argv) {
exit
(
0
);
}
str
cpy
(
(
char
*
)
&
pwd
[
i
],
(
char
*
)
&
buffer
);
mem
cpy
(
pwd
[
i
],
buffer
,
SHA256_BLOCK_SIZE
);
}
fclose
(
fp
);
...
...
@@ -65,39 +66,60 @@ int main(int argc, char** argv) {
exit
(
0
);
}
str
cpy
(
(
char
*
)
&
pwd
[
i
],
(
char
*
)
&
buffer
);
mem
cpy
(
pwd
[
i
],
buffer
,
SHA256_BLOCK_SIZE
);
}
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);
// }
// }
// }
// }
SHA256_CTX
ctx
;
BYTE
buf
[
SHA256_BLOCK_SIZE
];
// open output file
fp
=
fopen
(
OUTPUT_FILENAME
,
"w"
);
// violent crack PWD4
char
guess
[
5
];
guess
[
4
]
=
'\0'
;
int
checked
[
PWD4_NUMBERS
];
int_array_init
(
checked
,
PWD4_NUMBERS
);
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
;
// generate hash and check
sha256_init
(
&
ctx
);
sha256_update
(
&
ctx
,
(
BYTE
*
)
guess
,
4
);
sha256_final
(
&
ctx
,
buf
);
for
(
int
i
=
0
;
i
<
PWD4_NUMBERS
;
i
++
)
{
if
(
!
checked
[
i
]
&&
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
checked
[
i
]
=
1
;
printf
(
"%s %d
\n
"
,
guess
,
i
+
1
);
fprintf
(
fp
,
"%s %d
\n
"
,
guess
,
i
+
1
);
}
}
}
}
}
}
// crack PWD6
fclose
(
fp
);
}
else
if
(
argc
==
2
)
{
// This part for good guess
}
else
if
(
argc
==
3
)
{
FILE
*
fp
;
BYTE
buffer
[
BUFFERSIZE
];
FILE
*
wfp
;
BYTE
buffer
[
SHA256_BLOCK_SIZE
];
// read password file and store hashes passwords
fp
=
fopen
(
argv
[
2
],
"rb"
);
...
...
@@ -108,6 +130,7 @@ int main(int argc, char** argv) {
fseek
(
fp
,
0
,
SEEK_END
);
pwdsize
=
ftell
(
fp
);
fseek
(
fp
,
0
,
SEEK_SET
);
pwdcount
=
pwdsize
/
SHA256_BLOCK_SIZE
;
if
(
pwdsize
%
SHA256_BLOCK_SIZE
)
{
...
...
@@ -134,32 +157,49 @@ int main(int argc, char** argv) {
// read guess from file and check guess
fp
=
fopen
(
argv
[
1
],
"r"
);
wfp
=
fopen
(
OUTPUT_FILENAME
,
"w"
);
char
input
[
INPUTSIZE
];
SHA256_CTX
ctx
;
BYTE
buf
[
SHA256_BLOCK_SIZE
];
// create flag arrays to avoid repeat check
int
checked
[
pwdcount
];
int_array_init
(
checked
,
pwdcount
);
while
(
fgets
(
(
char
*
)
&
buffer
,
BUFFER
SIZE
,
fp
)
!=
NULL
)
{
while
(
fgets
(
input
,
INPUT
SIZE
,
fp
)
!=
NULL
)
{
// get rid of \n for buffer
buffer
[
strlen
((
char
*
)
&
buffer
)
-
1
]
=
'\0'
;
check_n_guess
(
buffer
,
pwd
,
pwdcount
,
checked
);
buffer
[
strlen
(
input
)
-
1
]
=
'\0'
;
// generate hash and check
sha256_init
(
&
ctx
);
sha256_update
(
&
ctx
,
(
BYTE
*
)
input
,
4
);
sha256_final
(
&
ctx
,
buf
);
for
(
int
i
=
0
;
i
<
pwdcount
;
i
++
)
{
if
(
!
checked
[
i
]
&&
!
memcmp
(
pwd
[
i
],
buf
,
SHA256_BLOCK_SIZE
))
{
checked
[
i
]
=
1
;
printf
(
"%s %d
\n
"
,
input
,
i
+
1
);
fprintf
(
wfp
,
"%s %d
\n
"
,
input
,
i
+
1
);
}
}
}
fclose
(
fp
);
fclose
(
wfp
);
}
return
0
;
}
void
check_guess
(
BYTE
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
],
void
check_guess
(
char
guess
[],
BYTE
pwd
[
PWD_NUMBERS
][
SHA256_BLOCK_SIZE
],
int
checked
[])
{
SHA256_CTX
ctx
;
BYTE
buf
[
SHA256_BLOCK_SIZE
];
size_t
guess_len
=
strlen
(
(
char
*
)
&
guess
);
size_t
guess_len
=
strlen
(
guess
);
int
i
;
sha256_init
(
&
ctx
);
sha256_update
(
&
ctx
,
guess
,
guess_len
);
sha256_update
(
&
ctx
,
(
BYTE
*
)
guess
,
guess_len
);
sha256_final
(
&
ctx
,
buf
);
if
(
guess_len
==
4
)
{
...
...
@@ -182,27 +222,6 @@ void check_guess(BYTE guess[], BYTE pwd[PWD_NUMBERS][SHA256_BLOCK_SIZE],
}
}
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.
found_pwds.txt
0 → 100644
+
10
−
0
View file @
e3a4e66a
1472 6
1482 7
1995 2
1gae 9
2goo 10
esit 3
sp*t 1
spOt 4
spot 5
xunz 8
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