-
-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added UDP Output to be consumed by Logstash #45
Open
blcarlson01
wants to merge
5
commits into
eth0izzle:master
Choose a base branch
from
blcarlson01:udp-logstash
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package core | |
import ( | ||
"fmt" | ||
"net/http" | ||
"net" | ||
"os" | ||
"regexp" | ||
"strings" | ||
|
@@ -66,7 +67,24 @@ func (l *Logger) Log(level int, format string, args ...interface{}) { | |
payload := fmt.Sprintf(session.Config.WebhookPayload, text) | ||
http.Post(session.Config.Webhook, "application/json", strings.NewReader(payload)) | ||
} | ||
|
||
|
||
if session.Config.Logstash != "" { | ||
text := colorStrip(fmt.Sprintf(format, args...)) | ||
payload := fmt.Sprintf(session.Config.Logstash, text) | ||
pc, err := net.ListenPacket("udp4", ":" + session.Config.LogstashPort) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer pc.Close() | ||
|
||
addr,err := net.ResolveUDPAddr("udp4", session.Config.Logstash) | ||
if err != nil { | ||
panic(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably also not panic because of a logstash connection |
||
} | ||
|
||
pc.WriteTo([]byte(payload), addr) | ||
} | ||
|
||
if level == FATAL { | ||
os.Exit(1) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Logstash Configuration | ||
|
||
## 1. Install ElasticSearch, Kibana, and Logstash | ||
- Follow the instructions on Elastic's website: https://www.elastic.co/guide/en/elastic-stack-get-started/current/get-started-elastic-stack.html | ||
|
||
## 2. Configure Logstash | ||
|
||
In the folder logstash/config/01-shhgit-pipeline.conf is a working example with a few Grok rules to process the incoming messages from shhgit. These Grok rules are imperfect, but should provide a starting point to improve upon. | ||
|
||
- 01-shhgit-pipeline.conf should be placed in the Logstash /etc/logstash/conf.d directory. | ||
- Update the output elasticsearch to point to your elasticsearch cluster | ||
|
||
## 3. Configure Kibana | ||
|
||
### Configure Pattern | ||
- Click the gear icon (management) in the lower left | ||
- Click Kibana -> Index Patters | ||
- Click Create New Index Pattern | ||
- Type "shhgit-*" into the input box, then click Next Step | ||
|
||
### Import Dashboard | ||
In your web browser go to Kibana's IP using port 5601 (ex: 192.168.0.1:5601) | ||
- Click Management -> Saved Objects | ||
- You can import the dashboard found in the dashboard folder via the Import button in the top-right corner. | ||
- shhgit Dashboard | ||
|
||
## TODO | ||
- Clean up Grok Rules | ||
- Add additional Grok Rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
input { | ||
udp { | ||
port => 8080 | ||
} | ||
} | ||
|
||
filter { | ||
|
||
if "Matching file" in [message] { | ||
grok { | ||
match => { "message" => "\[%{GREEDYDATA:location}\] Matching %{WORD:type} %{URIPATHPARAM:path} for %{GREEDYDATA:reason}\"" } | ||
} | ||
} | ||
|
||
if "match for" in [message] { | ||
grok { | ||
match => { "message" => "\[%{GREEDYDATA:location}\] %{NUMBER:number} match for %{GREEDYDATA:reason} in %{WORD:type} %{URIPATHPARAM:path}: %{URIPROTO:uriproto}://(?:%{USER:user}(?::%{GREEDYDATA:password}[^@]*)?@)?(?:%{URIHOST:urihost})?(?:%{URIPATHPARAM:uripathparam})?" } | ||
} | ||
} | ||
|
||
if "Potential secret" in [message] { | ||
grok { | ||
match => { "message" => "\[%{GREEDYDATA:location}\] %{GREEDYDATA:reason} in %{URIPATHPARAM:path} =%{SPACE}%{GREEDYDATA:secret}\"" } | ||
} | ||
} | ||
|
||
if "matches for" in [message] { | ||
grok { | ||
match => { "message" => "\[%{GREEDYDATA:location}\] %{NUMBER:number} matches for %{GREEDYDATA:reason} in %{WORD:type} %{GREEDYDATA:paths}\"" } | ||
} | ||
} | ||
|
||
if "Google OAuth Key" in [message] { | ||
grok { | ||
match => { "message" => "\[%{GREEDYDATA:location}\] %{NUMBER:number} matches for %{GREEDYDATA:reason} in %{WORD:type} %{GREEDYDATA:paths}\"" } | ||
} | ||
} | ||
|
||
if "Google Cloud API Key" in [message] { | ||
grok { | ||
match => { "message" => "\[%{GREEDYDATA:location}\] %{NUMBER:number} match for %{GREEDYDATA:reason} in %{WORD:type} %{URIPATHPARAM:path}:%{SPACE}%{GREEDYDATA:key}\"" } | ||
} | ||
} | ||
|
||
mutate { | ||
split => {"paths" => "," } | ||
} | ||
|
||
if "Cloning in to" in [message] { | ||
grok | ||
{ | ||
match => { "message" => "\[%{GREEDYDATA:location}\] Cloning in to %{URIPATH:path}\"" } | ||
add_tag => ["cloning"] | ||
} | ||
} | ||
|
||
if "Failed to" in [message] { | ||
grok | ||
{ | ||
match => { "message" => "\"%{GREEDYDATA:errorMessage}\"" } | ||
add_tag => ["failed"] | ||
} | ||
} | ||
|
||
if "Cloning failed" in [message] { | ||
grok | ||
{ | ||
match => { "message" => "\"%{GREEDYDATA:errorMessage}\"" } | ||
add_tag => ["failed"] | ||
} | ||
} | ||
|
||
if "started. Loaded" in [message] { | ||
grok | ||
{ | ||
match => { "message" => "\"%{GREEDYDATA:errorMessage}\"" } | ||
add_tag => ["info"] | ||
} | ||
} | ||
|
||
if "calls remain" in [message] { | ||
grok | ||
{ | ||
match => { "message" => "\"%{GREEDYDATA:errorMessage}\"" } | ||
add_tag => ["info"] | ||
} | ||
} | ||
|
||
mutate { | ||
rename => { "[message]" => "[original]"} | ||
} | ||
} | ||
|
||
output { | ||
elasticsearch { | ||
id => "shhgit" | ||
hosts => ["localhost:9200"] | ||
index => "shhgit-%{+YYYY.MM.dd}" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it should panic out "just" because the logstash session has an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, I can get those removed and pushed to the branch.