George Rees
George Rees

Reputation: 45

'int' object has no attribute 'format' - modifying snort rules

I'm currently writing a python script that configures snort for users and creates a rule to prevent access to tcp port 23, im trying to implement a feature that will allow you to enter a devices IP address and have them automatically added to the snort rule (IoTProtection.rules), however the problem is in the module adddevice() as when it runs I receive the error 'int' object has no attribute 'format'. I have tried setting the input to be a string but this doesn't seem to have worked, If anyone knows what the issue is it will be much appreciated, thanks!

[Full code] [1]: https://pastebin.com/LDjrDTU9

Troublesome module:

def adddevice():
    decision = input("If you would like to add further devices please enter 1, or press enter to end.")
    if decision == '1':        
        ip = input(str("Please enter additional devices IP here, including dots."))
        append = open("C:\\Snort\\Rules\\IoTProtection.rules",'a')
        added = append.write("reject tcp any any -> {} 23 (msg:""Unauthorized access to IoT device!""; sid:212345;rev:003; )")
        configured = added.format(str(ip))
        print("Device added!")
else:
    quit()

Upvotes: 0

Views: 5081

Answers (1)

Chuk Ultima
Chuk Ultima

Reputation: 1037

You mean to put the value in the string message, not the result of 'append()'. try this instead :

message = "reject tcp any any -> {} 23 (msg:""Unauthorized access to IoT device!""; sid:212345;rev:003; )"
message = message.format(str(ip))
added = append.write(message)

Upvotes: 2

Related Questions