-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwncheck
More file actions
executable file
·175 lines (136 loc) · 3.93 KB
/
pwncheck
File metadata and controls
executable file
·175 lines (136 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env perl
package PwnCheck;
use v5.18.4;
use strict;
use warnings;
use feature qw(say);
use FindBin qw($Bin);
use lib "$Bin/lib";
use HIBP::V3;
use Getopt::Long;
use JSON;
use HTTP::Tiny;
our $VERSION = '0.0.1';
sub help {
say q{
NAME
pwncheck
DESCRIPTION
Check for account or password pwnage.
SYNOPSIS
pwncheck [...option] [...value]
OPTIONS
-h, --help
-d, --data-classes prints out a list of data classes
-p, --password-status <password> checks if password(s) have been pwned
-ab, --account-breaches <account> print a list of breaches found for the account
-ap, --account-pastes <account> print a list of pastes found for the account
-bs, --breached-site <site> print breach details about a specific site
-bS, --breached-sites print a list of all known site breaches
};
exit;
}
sub pwncheck {
return shift->{'__pwncheck'} ||= do {
return HIBP::V3->new;
};
}
sub get_opts {
my $self = shift;
GetOptions(
'h|help|?' => sub { &help },
'd|data-classes' => \$self->{'data-classes'},
'p|password=s' => \$self->{'password-status'},
'b|breaches=s' => \$self->{'account-breaches'},
'P|pastes=s' => \$self->{'account-pastes'},
'bs|breached-site=s' => \$self->{'breached-site'},
'bS|breached-sites' => \$self->{'breached-sites'},
'v|verbose' => \$self->{'verbose'},
);
}
sub new {
my $blessed = bless {}, shift;
$blessed->get_opts;
return $blessed;
}
sub run {
my $self = shift;
$self->get_password_status if $self->{'password-status'};
$self->get_data_classes if $self->{'data-classes'};
$self->get_account_breaches if $self->{'account-breaches'};
$self->get_account_pastes if $self->{'account-pastes'};
$self->get_breached_site if $self->{'breached-site'};
$self->get_breached_sites if $self->{'breached-sites'};
}
sub http {
return shift->{'__http'} //= do {
HTTP::Tiny->new;
};
}
sub get_multi_val {
my $self = shift;
my $val = shift;
my $resp = $val;
if ($val =~ m{^https://}) {
my $url = $val;
my $head = $self->http->head($val);
my $ctype = $head->{'headers'}->{'content-type'} // 0;
my $status = $head->{'status'};
if ($ctype =~ m{^text/plain;} && $status == 200) {
my $get = $self->http->get($url)->{'content'} // '';
$get =~ s/\r//g;
my @vals = split /\n/, $get;
return \@vals;
}
}
elsif (-f $val) {
my @vals = ();
open my $fh, '<', $val or die "$!\n";
while (my $line = <$fh>) {
chomp $line;
push @vals, $line;
}
close $fh;
return \@vals;
}
return $resp;
}
sub get_password_status {
my $self = shift;
my $pwncheck = $self->pwncheck;
my $password = $self->get_multi_val($self->{'password-status'});
my $status = $pwncheck->get_password_status($password);
say encode_json $status;
}
sub get_account_breaches {
my $self = shift;
my $pwncheck = $self->pwncheck;
my $account = $self->get_multi_val($self->{'account-breaches'});
say $pwncheck->get_account_breaches($account);
}
sub get_account_pastes {
my $self = shift;
my $pwncheck = $self->pwncheck;
my $account = $self->get_multi_val($self->{'account-pastes'});
say $pwncheck->get_account_pastes($account);
}
sub get_data_classes {
my $self = shift;
my $pwncheck = $self->pwncheck;
say $pwncheck->get_data_classes;
}
sub get_breached_sites {
my $self = shift;
my $filter = shift // '';
my $pwncheck = $self->pwncheck;
say $pwncheck->get_breached_sites;
}
sub get_breached_site {
my $self = shift;
say $self->pwncheck->get_breached_site(
$self->{'breached-site'},
);
}
1;
PwnCheck->new->run;
exit;