forked from robertdavidgraham/masscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
out-certs.c
92 lines (80 loc) · 2.53 KB
/
out-certs.c
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
#include "output.h"
#include "masscan-app.h"
#include "masscan-status.h"
#include "string_s.h"
#include <ctype.h>
/****************************************************************************
****************************************************************************/
static void
cert_out_open(struct Output *out, FILE *fp)
{
UNUSEDPARM(out);
UNUSEDPARM(fp);
}
/****************************************************************************
****************************************************************************/
static void
cert_out_close(struct Output *out, FILE *fp)
{
UNUSEDPARM(out);
fprintf(fp, "{finished: 1}\n");
}
/******************************************************************************
******************************************************************************/
static void
cert_out_status(struct Output *out, FILE *fp, time_t timestamp, int status,
unsigned ip, unsigned ip_proto, unsigned port, unsigned reason, unsigned ttl)
{
/* certificates only come with banner info, so there is no port info
* to report */
UNUSEDPARM(out);
UNUSEDPARM(fp);
UNUSEDPARM(timestamp);
UNUSEDPARM(status);
UNUSEDPARM(ip);
UNUSEDPARM(ip_proto);
UNUSEDPARM(port);
UNUSEDPARM(reason);
UNUSEDPARM(ttl);
}
/******************************************************************************
******************************************************************************/
static void
cert_out_banner(struct Output *out, FILE *fp, time_t timestamp,
unsigned ip, unsigned ip_proto, unsigned port,
enum ApplicationProtocol proto,
unsigned ttl,
const unsigned char *px, unsigned length)
{
unsigned i;
UNUSEDPARM(ip_proto);
UNUSEDPARM(ip);
UNUSEDPARM(timestamp);
UNUSEDPARM(fp);
UNUSEDPARM(out);
UNUSEDPARM(ttl);
UNUSEDPARM(proto);
UNUSEDPARM(port);
if (length > 5 && memcmp(px, "cert:", 5) == 0) {
px += 5;
length -= 5;
}
printf("-----BEGIN CERTIFICATE-----\n");
for (i=0; i<length; i += 72) {
unsigned len = length - i;
if (len > 72)
len = 72;
printf("%.*s\n", len, px+i);
}
printf("-----END CERTIFICATE-----\n");
}
/****************************************************************************
****************************************************************************/
const struct OutputType certs_output = {
"cert",
0,
cert_out_open,
cert_out_close,
cert_out_status,
cert_out_banner
};