This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
image.py
78 lines (60 loc) · 2.41 KB
/
image.py
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
# -*- coding: utf-8 -*-
# This file is part of Viper - https://github.com/viper-framework/viper
# See the file 'LICENSE' for copying permission.
from io import BytesIO
import logging
try:
import requests
HAVE_REQUESTS = True
except ImportError:
HAVE_REQUESTS = False
from viper.common.out import bold
from viper.common.abstracts import Module
from viper.core.session import __sessions__
from viper.core.config import __config__
log = logging.getLogger('viper')
cfg = __config__
class Image(Module):
cmd = 'image'
description = 'Perform analysis on images'
authors = ['nex']
def __init__(self):
super(Image, self).__init__()
self.parser.add_argument('-g', '--ghiro', action='store_true', help='Upload the file to imageforensic.org and retrieve report')
def ghiro(self):
if not HAVE_REQUESTS:
self.log('error', "Missing dependency, install requests (`pip install requests`)")
return
payload = dict(private='true', json='true')
files = dict(image=BytesIO(__sessions__.current.file.data))
response = requests.post('http://www.imageforensic.org/api/submit/', data=payload, files=files,
proxies=cfg.http_client.proxies, verify=cfg.http_client.verify, cert=cfg.http_client.cert)
results = response.json()
if results['success']:
report = results['report']
if len(report['signatures']) > 0:
self.log('', bold("Signatures:"))
for signature in report['signatures']:
self.log('item', signature['description'])
for k, v in report.items():
if k == 'signatures':
continue
if isinstance(v, dict):
for k1, v1 in v.items():
self.log('info', '{}: {}'.format(k1, v1))
else:
self.log('info', '{}: {}'.format(k, v))
else:
self.log('error', "The analysis failed")
def run(self):
super(Image, self).run()
if self.args is None:
return
if not __sessions__.is_set():
self.log('error', "No open session. This command expects a file to be open.")
return
if self.args.ghiro:
self.ghiro()
else:
self.log('error', 'At least one of the parameters is required')
self.usage()