|
@@ -0,0 +1,30 @@
|
|
|
|
+#!/usr/bin/env python3
|
|
|
|
+import sys
|
|
|
|
+import email
|
|
|
|
+m = email.message_from_bytes(sys.stdin.buffer.read())
|
|
|
|
+
|
|
|
|
+INJECTED = {
|
|
|
|
+ 'text/plain': False,
|
|
|
|
+ 'text/html': False,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+def inject(m):
|
|
|
|
+ c = m.get_content_type()
|
|
|
|
+ payload = m.get_payload()
|
|
|
|
+ if c == 'text/plain':
|
|
|
|
+ payload = 'BANNER\r' + payload
|
|
|
|
+ if c == 'text/html':
|
|
|
|
+ payload = payload.replace('</body>', '<p>BANNER</p></body>')
|
|
|
|
+ m.set_payload(payload)
|
|
|
|
+
|
|
|
|
+def visit(m):
|
|
|
|
+ c = m.get_content_type()
|
|
|
|
+ if c in ('text/plain', 'text/html'):
|
|
|
|
+ if INJECTED[c]: return
|
|
|
|
+ inject(m)
|
|
|
|
+ INJECTED[c] = True
|
|
|
|
+
|
|
|
|
+for _m in m.walk():
|
|
|
|
+ visit(_m)
|
|
|
|
+
|
|
|
|
+sys.stdout.buffer.write(m.as_bytes())
|