-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDaily-InfoSec-News.ps1
188 lines (156 loc) · 6.83 KB
/
Daily-InfoSec-News.ps1
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
176
177
178
179
180
181
182
183
184
185
186
187
188
# Force TLS1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Get Atom Feed for TheRegister Security
$ElReg = Invoke-WebRequest -Uri "https://www.theregister.com/security/headlines.atom" -UseBasicParsing -ContentType "application/xml"
If ($ElReg.StatusCode -ne "200") {
# Feed failed to respond.
Write-Host "Message: $($ElReg.StatusCode) $($ElReg.StatusDescription)"
}
# Get RSS feed for ZDNet Security
$ZDNet = Invoke-WebRequest -Uri "https://www.zdnet.com/topic/security/rss.xml" -UseBasicParsing -ContentType "application/xml"
If ($ZDNet.StatusCode -ne "200") {
# Feed fails to respond
Write-Host "Message: $($ZDNet.StatusCode) $($ZDNet.StatusDescription)"
}
# Get RSS feed for KrebsOnSecurity
$Krebs = Invoke-WebRequest -Uri "https://krebsonsecurity.com/feed/" -UseBasicParsing -ContentType "application/xml"
If ($Krebs.StatusCode -ne "200") {
# Feed failed to respond.
Write-Host "Message: $($Krebs.StatusCode) $($Krebs.StatusDescription)"
}
# Get RSS feed for TheHackerNews
$THN = Invoke-WebRequest -Uri "https://feeds.feedburner.com/TheHackersNews?format=xml" -UseBasicParsing -ContentType "application/xml"
If ($THN.StatusCode -ne "200") {
# Feed failed to respond.
Write-Host "Message: $($THN.StatusCode) $($THN.StatusDescription)"
}
# Get RSS feed for ThreatPost
$TP = Invoke-WebRequest -Uri "https://threatpost.com/feed/" -UseBasicParsing -ContentType "application/xml"
If ($TP.StatusCode -ne "200") {
# Feed failed to respond.
Write-Host "Message: $($TP.StatusCode) $($TP.StatusDescription)"
}
# Set feed content
$ElRegFeedXml = [xml]$ElReg.Content
$ZDNetFeedXml = [xml]$ZDNet.Content
$KrebsFeedXml = [xml]$Krebs.Content
$THNFeedXml = [xml]$THN.Content
$TPFeedXml = [xml]$TP.Content
$Now = Get-Date
# Extract TheRegister Security articles updated within the last 26 hours
$items = $ElRegFeedXml.feed.entry
$ElRegNews = ForEach ($item in $items) {
If (($Now - [datetime]$item.updated).TotalMinutes -le 1560) {
$title = $item.title.'#text'
$link = $item.link.href
$desc = $item.summary.'#text'
$updated = [datetime]$item.updated
$source = $ElRegFeedXml.feed.title
[PSCustomObject]@{title=$title;link=$link;source=$source;updated=$updated}
}
}
$ElRegNews | Select-Object -Property Title, Link, Source, Updated #| Out-GridView
# Extract ZDNet Security articles updated within the last 26 hours
$items = $ZDNetFeedXml.rss.channel.Item
$ZDNetNews = ForEach ($item in $items) {
If (($Now - [datetime]$item.pubDate).TotalMinutes -le 1560) {
$title = $item.title
$link = $item.link
$desc = $item.description
$updated = [datetime]$item.pubDate
$source = $ZDNetFeedXml.rss.channel.generator + " " + $ZDNetFeedXml.rss.channel.category
[PSCustomObject]@{title=$title;link=$link;source=$source;updated=$updated}
}
}
$ZDNetNews | Select-Object -Property Title, Link, Source, Updated | Out-GridView
# Extract KrebsOnSecurity articles updated within the last 26 hours
$items = $KrebsFeedXml.rss.channel.item
$KrebsNews = ForEach ($item in $items) {
If (($Now - [datetime]$item.pubDate).TotalMinutes -le 1560) {
$title = $item.title
$link = $item.link
$desc = $item.description
$updated = [datetime]$item.pubDate
$source = $KrebsFeedXml.rss.channel.title
[PSCustomObject]@{title=$title;link=$link;source=$source;updated=$updated}
}
}
$KrebsNews | Select-Object -Property Title, Link, Source, Updated #| Out-GridView
# Extract TheHackerNews articles updated within the last 30 hours
$items = $THNFeedXml.rss.channel.Item
$THNNews = ForEach ($item in $items) {
$item.link = $item.link -replace "http://", "https://"
$time = $item.pubDate -replace '.{4}$'
$time = $time.substring(5)
If (($Now - [datetime]$time).TotalMinutes -le 1800) {
$title = $item.title
$link = $item.link
$desc = $item.description
$updated = $time
$source = $THNFeedXml.rss.channel.title
[PSCustomObject]@{title=$title;link=$link;source=$source;updated=$time}
}
}
$THNnews | Select-Object -Property Title, Link, Source, Updated #| Out-GridView
# Extract ThreatPost articles updated within the last 26 hours
$items = $TPFeedXml.rss.channel.Item
$TPNews = ForEach ($item in $items) {
If (($Now - [datetime]$item.pubDate).TotalMinutes -le 1560) {
$title = $item.title
$link = $item.link
$updated = [datetime]$item.pubDate
$source = $TPFeedXml.rss.channel.title
[PSCustomObject]@{title=$title;link=$link;source=$source;updated=$updated}
}
}
$TPNews | Select-Object -Property Title, Link, Source, Updated #| Out-GridView
# CSS 2.0 styling
$css = @'
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
'@
If ($ElRegNews.Count -eq 0 -and $ZDNetNews.Count -eq 0 -and $KrebsNews.Count -eq 0 -and $THNNews.Count -eq 0 -and $TPNews.Count -eq 0) {
#Write-Host "nothing to report"
$emailNoNews = @{
To = "email-address-here"
From = "email-address-here"
Subject = "Security News: " + $(Get-Date -UFormat "%A %d %B %Y")
Body = "<span style='font-family:Calibri;font-size:11pt'>" + "Hello xxxxxxx" + "<br><br>" + "Nothing to report at the moment, check back tomorrow." + "<br><br>" + "</span>" | Out-String
BodyAsHtml = $true
SmtpServer = "smtp-server-here"
}
Send-MailMessage @emailNoNews
} else {
$emailNewsBody = $ElRegNews + $ZDNetNews + $KrebsNews + $THNnews + $TPNews | ConvertTo-Html -Head $css
# Replace some dodgy encodings
$emailNewsBody = $emailNewsBody -replace "â", "-"
$emailNewsBody = $emailNewsBody -replace "Â", ""
$emailNewsBody = $emailNewsBody -replace "£", "`£"
$emailNewsBody = $emailNewsBody -replace "<i>", ""
$emailNewsBody = $emailNewsBody -replace "</i>", ""
$emailNewsBody = $emailNewsBody -replace "‘", "'"
$emailNewsBody = $emailNewsBody -replace "’", "'"
# Send email
$emailNews = @{
To = "email-address-here"
From = "email-address-here"
Subject = "Security News: " + $(Get-Date -UFormat "%A %d %B %Y")
Body = "<span style='font-family:Calibri;font-size:11pt'>" + "Hello xxxxxxx" + "<br><br>" + "Please find below a selection of Security news from the past 24 hours: " + "<br><br>" + $emailNewsBody + "</span>" | Out-String
BodyAsHtml = $true
SmtpServer = "smtp-server-here"
}
Send-MailMessage @emailNews
}