aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/scripts/suricatasc/suricatasc.in
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-09-09 22:21:41 -0700
committerAshlee Young <ashlee@onosfw.com>2015-09-09 22:21:41 -0700
commit8879b125d26e8db1a5633de5a9c692eb2d1c4f83 (patch)
treec7259d85a991b83dfa85ab2e339360669fc1f58e /framework/src/suricata/scripts/suricatasc/suricatasc.in
parent13d05bc8458758ee39cb829098241e89616717ee (diff)
suricata checkin based on commit id a4bce14770beee46a537eda3c3f6e8e8565d5d0a
Change-Id: I9a214fa0ee95e58fc640e50bd604dac7f42db48f
Diffstat (limited to 'framework/src/suricata/scripts/suricatasc/suricatasc.in')
-rwxr-xr-xframework/src/suricata/scripts/suricatasc/suricatasc.in65
1 files changed, 65 insertions, 0 deletions
diff --git a/framework/src/suricata/scripts/suricatasc/suricatasc.in b/framework/src/suricata/scripts/suricatasc/suricatasc.in
new file mode 100755
index 00000000..63b4ebfa
--- /dev/null
+++ b/framework/src/suricata/scripts/suricatasc/suricatasc.in
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+# Copyright(C) 2013 Open Information Security Foundation
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+from __future__ import print_function
+import sys
+import argparse
+from suricatasc import *
+
+parser = argparse.ArgumentParser(prog='suricatasc', description='Client for Suricata unix socket')
+parser.add_argument('-v', '--verbose', action='store_const', const=True, help='verbose output (including JSON dump)')
+parser.add_argument('-c', '--command', default=None, help='execute on single command and return JSON')
+parser.add_argument('socket', metavar='socket', nargs='?', help='socket file to connnect to', default=None)
+args = parser.parse_args()
+
+if args.socket != None:
+ SOCKET_PATH = args.socket
+else:
+ SOCKET_PATH = "@e_localstatedir@/suricata-command.socket"
+
+sc = SuricataSC(SOCKET_PATH, verbose=args.verbose)
+try:
+ sc.connect()
+except SuricataNetException as err:
+ print("Unable to connect to socket %s: %s" % (SOCKET_PATH, err), file=sys.stderr)
+ sys.exit(1)
+except SuricataReturnException as err:
+ print("Unable to negotiate version with server: %s" % (err), file=sys.stderr)
+ sys.exit(1)
+
+if args.command:
+ (command, arguments) = sc.parse_command(args.command)
+ res = sc.send_command(command, arguments)
+ print(json.dumps(res))
+ sc.close()
+ if res['return'] == 'OK':
+ sys.exit(0)
+ else:
+ sys.exit(1)
+
+try:
+ sc.interactive()
+except SuricataNetException as err:
+ print("Communication error: %s" % (err))
+ sys.exit(1)
+except SuricataReturnException as err:
+ print("Invalid return from server: %s" % (err))
+ sys.exit(1)
+
+print("[+] Quit command client")
+
+sc.close()