Skip to content

Wordpress & Docker#240

Merged
aarontp merged 8 commits into
google:masterfrom
tomchop:wordpress
Sep 17, 2018
Merged

Wordpress & Docker#240
aarontp merged 8 commits into
google:masterfrom
tomchop:wordpress

Conversation

@tomchop

@tomchop tomchop commented Aug 23, 2018

Copy link
Copy Markdown
Collaborator

This PR adds a couple Workers and analysis modules:

  • Docker logs extraction job: Extract logs from Docker containers
  • Wordpress analysis worker: Analyze Wordpress web access logs and assess the likelihood of compromise.

@tomchop tomchop requested a review from Onager August 23, 2018 11:16
@tomchop tomchop requested a review from aarontp August 23, 2018 11:18
@aarontp

aarontp commented Aug 24, 2018

Copy link
Copy Markdown
Member

Thanks for the PR! I didn't get a chance to look at this today, but I'll take a look tomorrow.

Onager
Onager previously requested changes Aug 27, 2018
Comment thread turbinia/jobs/analysis/docker_logs.py Outdated
Comment thread turbinia/jobs/analysis/docker_logs.py Outdated
Comment thread turbinia/jobs/analysis/docker_logs.py Outdated
Comment thread turbinia/workers/analysis/wordpress_test.py Outdated

@aarontp aarontp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a couple minor comments.

Comment thread turbinia/workers/analysis/wordpress.py Outdated

# Add the resulting evidence to the result object.
result.add_evidence(output_evidence, evidence.config)
result.close(self, success=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a 'status' parameter here with a summary of what was found? I think the first line of the 'analysis' variable is close to what would be good. See more on this below.

Comment thread turbinia/workers/analysis/wordpress.py Outdated
self._get_timestamp(log_line), edited_file))

if findings:
findings.insert(0, 'Potential Wordpress compromise found:')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we slightly change this, then the first line of what is returned from this function can be easily passed in as the 'status' parameter to result.close(). Maybe something along the lines of 'Potential Wordpress compromise found (N findings)' or 'N findings related to potential Wordpress compromise'?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll change it to "Wordpress access logs found (install, theme editing)". It's less misleading than "compromise" in the case we only have one finding.

Comment thread turbinia/workers/analysis/wordpress.py Outdated
findings.insert(0, 'Potential Wordpress compromise found:')
return '\n'.join(findings)

return 'No theme editing found in Wordpress access logs'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this no theme editing or installations? Maybe either enumerate or just keep it generic?

@tomchop tomchop Aug 29, 2018

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 'No Wordpress install or theme editing found in access logs'

@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Google Inc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the date maybe?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread turbinia/jobs/analysis/docker_logs.py Outdated
in evidence]
return tasks

class DockerLogAnalysisJob(TurbiniaJob):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I missed one big thing here. Why would these Tasks only be specific to Docker containers[1]. Can we at minimum add separate Tasks for the local system logs? I'm assuming that shouldn't require any changes to the Tasks themselves, and is maybe just another Artifact that needs to be referenced?

We don't have to do it in this PR, but I wonder if there is a better way to handle this architecturally as well, for example possibly adding a Docker enumeration Task that creates a new DockerContainer evidence type. That might not work without some extra effort though, because the two evidence types may be too fundamentally different to be handled generically in a Task. I wonder if there is a reliable way to do a mount of the container image to make it more generic for the Tasks? cc: @berggren and @rgayon for thoughts on this part.

[1] This brings up another big point that we should make our other analysis Tasks should also be looking to 'recurse' into Docker containers as well

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this came up during a chat with @rgayon earlier this week.

In theory we could use the exact same plugin with a minor change in the artifact. The "docker log" format is slightly different than a normal nginx or apache access log (it's, essentially, access logs wrapped in JSON). The analysis logic ignores the JSON and just greps through the output, which will work on both JSON-wrapped logs and regular access logs.

I'm happy to rename DockerLogExtractionJob to AccessLogExtractionJob to reflect regular log grabbing using different artifacts (nginx, apache, and also docker) and passing that on to the existing Task. Can we just add an extra FileArtifactExtractionTask in L51.

Finally, there's a bit of a nuance in Docker logs - the cases I was thinking to tackle with this Job was when the container logs to stdout and Docker logs that in its log. In theses cases, if you mount the docker container as a regular FS, you won't find logs anywhere in the mountpoint since they are all sent outside of the container.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be great if we can rename it and just add an extra Artifact extraction. As you suggest, just adding it to L51 should work if there is already a suitable artifact type.

@aarontp

aarontp commented Aug 30, 2018

Copy link
Copy Markdown
Member

Let me know when to take another look. It looks like some tests are failing as of now.

@tomchop

tomchop commented Sep 5, 2018

Copy link
Copy Markdown
Collaborator Author

Weird, tests seem to be passing on my VM and on Travis. Codefactor is blocking on a cyclic import but I think it's not WAI (all imports are done in get_jobs). Thoughts?

@tomchop tomchop requested review from Onager and aarontp September 5, 2018 13:14
@aarontp

aarontp commented Sep 5, 2018

Copy link
Copy Markdown
Member

Yeah, not sure what is up with the codefactor cyclic import issue. I don't see anything that should be causing that. Other than that, is this ready for review? Once it's ready I can do a quick check to make sure that the tests pass in my environment, and if they do I think we can ignore the codefactor issue.

@Onager

Onager commented Sep 5, 2018

Copy link
Copy Markdown
Contributor

@tomchop Does local pylint also complain about a cyclic import?

@tomchop

tomchop commented Sep 6, 2018

Copy link
Copy Markdown
Collaborator Author

@aarontp Yeah I fixed the comments, should be ready for review
@Onager No cyclic import error on local pylint

@aarontp

aarontp commented Sep 7, 2018

Copy link
Copy Markdown
Member

Sorry, I wasn't able to get this done today. I'll take a look in the morning.

Comment thread test_data/wordpress_access_logs.txt Outdated
@@ -0,0 +1,19 @@
{"log":"10.128.0.2 - - [27/Jun/2018:19:29:54 +0000] \"POST /wp-admin/install.php?step=2 HTTP/1.1\" 200 872 \"-\" \"Mozilla/5.0 (Windows; U; Windows NT 10.0) http/2.8.11 Tcl/8.6.7\"\n","strea

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file formatted correctly? There are newlines mid-line in a lot of places.

Also, wow, that's an ugly log format, :).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this is how Kubernetes logs things when it logs from stdout. I'll change this to "normal" access log fiels

@aarontp aarontp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I think this looks much better handling Docker this way, thanks for changing that up. Mostly only some minor comments/nits (feel free to ignore them), but the couple things I wanted to cover is the test data format, and how gzip'd files are handled. Thanks!

Comment thread turbinia/jobs/analysis/http_access_logs.py
Comment thread turbinia/jobs/analysis/http_access_logs.py Outdated
Comment thread turbinia/workers/analysis/wordpress.py
Comment thread turbinia/workers/analysis/wordpress.py Outdated
Comment thread turbinia/workers/analysis/wordpress.py Outdated
@Onager Onager mentioned this pull request Sep 10, 2018
@tomchop tomchop requested a review from aarontp September 13, 2018 08:52
@rgayon

rgayon commented Sep 14, 2018

Copy link
Copy Markdown
Collaborator

FYI, I'm renaming the "docker log" artifacts in ForensicArtifacts/artifacts#291 as those are actually very specific to GKE environments.

@aarontp aarontp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@aarontp aarontp dismissed Onager’s stale review September 17, 2018 21:00

I'm not sure why github thinks this review is outstanding, the issues raised in the review have already been addressed.

@aarontp aarontp merged commit 55e9a6b into google:master Sep 17, 2018
Onager pushed a commit to Onager/turbinia that referenced this pull request Sep 21, 2018
* Docker & Wordpress

* Cleanup

* Fix reviewer comments

* Rename classes & address reviewer comments.

* Fix reviewer comments + add support for gzipped files

* Fix ugly logs

* Fix broken text
@tomchop tomchop deleted the wordpress branch August 6, 2019 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants