Skip to content

Commit 54161db

Browse files
committed
Add chat-bot PSE
1 parent 5ed2516 commit 54161db

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

pse/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ These scripts currently only serve as a way to give you an idea about how this c
3232
<td>✔</td>
3333
<td>✔</td>
3434
</tr>
35+
<tr>
36+
<td><a href="chat-bot">chat-bot</a></td>
37+
<td>Basic <i>dummy</i> chat bot that wants you to greet it, tell it your name and will then ask you a couple of questions.</td>
38+
<td>✔</td>
39+
<td>✔</td>
40+
</tr>
3541
</tbody>
3642
</table>
3743

pse/chat-bot/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# PSE: Chat bot
2+
3+
A simple script that makes the remote peer site behave like a bot replying to your questions.
4+
5+
## Usage
6+
7+
Use high verbosity to see how the data gets transformed.
8+
9+
### Server
10+
11+
**Note:** The server side is using `/bin/cat` as its command in order to echo the messages back to the client. Then we hook into the sending part and simply overwrite the replies based on the received input.
12+
```bash
13+
pwncat -vvvv -l localhost 4444 \
14+
--exec /bin/cat \
15+
--script-send pse/chat-bot/pse-chat_bot.py
16+
```
17+
18+
### Client
19+
```bash
20+
pwncat localhost 4444
21+
```
22+
23+
### In action
24+
25+
The following shows it in action. `>` represents sending data to the server and `<` are the replies.
26+
```
27+
> some data
28+
< Be polite and greet first.
29+
> hi
30+
< Nice to meet you, what is your name?
31+
> cytopia
32+
< OK, I call you: cytopia
33+
> that's right
34+
< Hi cytopia, How is the weather?
35+
> it's pretty good
36+
< Hi cytopia, Why are you chatting to a bot?
37+
> I don't know
38+
< Hi cytopia, Are you bored?
39+
> Maybe
40+
< Hi cytopia, Have you had dinner?
41+
```

pse/chat-bot/pse-chat_bot.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Greet Bot."""
2+
3+
PSE_BOT_QUESTIONS = [
4+
"How is the weather?",
5+
"How old are you?",
6+
"What do you do today?",
7+
"Do you like Python?",
8+
"Have you had dinner?",
9+
"Can you guess my name?",
10+
"Are you bored?",
11+
"Why are you chatting to a bot?",
12+
"Do you expect me to answer properly?",
13+
]
14+
15+
16+
def transform(data, pse):
17+
"""Transform."""
18+
global PSE_BOT_QUESTIONS
19+
20+
# Setup custom data structure
21+
if pse.store is None:
22+
pse.store = {}
23+
if "bot" not in pse.store:
24+
pse.store["bot"] = {}
25+
26+
from random import randrange
27+
28+
if "greet" not in pse.store["bot"]:
29+
if any(x in data for x in ["hi", "helo", "halo", "hallo", "hello"]):
30+
pse.store["bot"]["greet"] = True
31+
return "Nice to meet you, what is your name?\n"
32+
return "Be polite and greet first.\n"
33+
34+
if "name" not in pse.store["bot"]:
35+
pse.store["bot"]["name"] = data.rstrip()
36+
return "OK, I call you: {}".format(data)
37+
38+
index = randrange(0, len(PSE_BOT_QUESTIONS)-1)
39+
return "Hi {}, {}\n".format(pse.store["bot"]["name"], PSE_BOT_QUESTIONS[index])

0 commit comments

Comments
 (0)