mirror of
https://github.com/cowrie/cowrie.git
synced 2025-07-01 18:07:27 -04:00
update head to take -c. update quotes for remotesyslog (#2318)
This commit is contained in:
@ -181,32 +181,34 @@ class Command_head(HoneyPotCommand):
|
|||||||
head command
|
head command
|
||||||
"""
|
"""
|
||||||
|
|
||||||
n: int = 10
|
linecount: int = 10
|
||||||
|
bytecount: int = 0
|
||||||
|
|
||||||
def head_application(self, contents: bytes) -> None:
|
def head_application(self, contents: bytes) -> None:
|
||||||
i = 0
|
if self.bytecount:
|
||||||
contentsplit = contents.split(b"\n")
|
self.writeBytes(contents[: self.bytecount])
|
||||||
for line in contentsplit:
|
elif self.linecount:
|
||||||
if i < self.n:
|
linesplit = contents.split(b"\n")
|
||||||
|
for line in linesplit[: self.linecount]:
|
||||||
self.writeBytes(line + b"\n")
|
self.writeBytes(line + b"\n")
|
||||||
i += 1
|
|
||||||
|
|
||||||
def head_get_file_contents(self, filename: str) -> None:
|
def head_get_file_contents(self, filename: str) -> None:
|
||||||
try:
|
try:
|
||||||
contents = self.fs.file_contents(filename)
|
contents = self.fs.file_contents(filename)
|
||||||
self.head_application(contents)
|
self.head_application(contents)
|
||||||
except Exception:
|
except fs.FileNotFound:
|
||||||
self.errorWrite(
|
self.errorWrite(
|
||||||
f"head: cannot open `{filename}' for reading: No such file or directory\n"
|
f"head: cannot open `{filename}' for reading: No such file or directory\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
def start(self) -> None:
|
def start(self) -> None:
|
||||||
self.n = 10
|
self.lines: int = 10
|
||||||
|
self.bytecount: int = 0
|
||||||
if not self.args or self.args[0] == ">":
|
if not self.args or self.args[0] == ">":
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
optlist, args = getopt.getopt(self.args, "n:")
|
optlist, args = getopt.getopt(self.args, "c:n:")
|
||||||
except getopt.GetoptError as err:
|
except getopt.GetoptError as err:
|
||||||
self.errorWrite(f"head: invalid option -- '{err.opt}'\n")
|
self.errorWrite(f"head: invalid option -- '{err.opt}'\n")
|
||||||
self.exit()
|
self.exit()
|
||||||
@ -215,9 +217,16 @@ class Command_head(HoneyPotCommand):
|
|||||||
for opt in optlist:
|
for opt in optlist:
|
||||||
if opt[0] == "-n":
|
if opt[0] == "-n":
|
||||||
if not opt[1].isdigit():
|
if not opt[1].isdigit():
|
||||||
self.errorWrite(f"head: illegal offset -- {opt[1]}\n")
|
self.errorWrite(f"head: invalid number of lines: `{opt[1]}`\n")
|
||||||
else:
|
else:
|
||||||
self.n = int(opt[1])
|
self.linecount = int(opt[1])
|
||||||
|
self.bytecount = 0
|
||||||
|
elif opt[0] == "-c":
|
||||||
|
if not opt[1].isdigit():
|
||||||
|
self.errorWrite(f"head: invalid number of bytes: `{opt[1]}`\n")
|
||||||
|
else:
|
||||||
|
self.bytecount = int(opt[1])
|
||||||
|
self.linecount = 0
|
||||||
|
|
||||||
if not self.input_data:
|
if not self.input_data:
|
||||||
files = self.check_arguments("head", args)
|
files = self.check_arguments("head", args)
|
||||||
|
|||||||
@ -23,7 +23,7 @@ class Output(cowrie.core.output.Output):
|
|||||||
|
|
||||||
self.logger = logging.getLogger("cowrieLogger")
|
self.logger = logging.getLogger("cowrieLogger")
|
||||||
|
|
||||||
self.handler = logging.handlers.SysLogHandler(address = (self.host, self.port), socktype= None if protocol == 'udp' else socket.SOCK_STREAM)
|
self.handler = logging.handlers.SysLogHandler(address = (self.host, self.port), socktype= None if protocol == "udp" else socket.SOCK_STREAM)
|
||||||
|
|
||||||
self.logger.addHandler(
|
self.logger.addHandler(
|
||||||
self.handler
|
self.handler
|
||||||
@ -40,4 +40,4 @@ class Output(cowrie.core.output.Output):
|
|||||||
if i.startswith("log_") or i == "time" or i == "system":
|
if i.startswith("log_") or i == "time" or i == "system":
|
||||||
del event[i]
|
del event[i]
|
||||||
|
|
||||||
self.logger.warning(repr(event)+'\n')
|
self.logger.warning(repr(event)+"\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user