如何自动进行 telnet 端口 25 测试?

发布于 2024-07-15 08:30:22 字数 1066 浏览 9 评论 0原文

我需要在 telnet 中进行大量测试。 我正在研究一些方法来自动检测我们的电子邮件服务器上的字典攻击,然后限制它们,或将它们列入黑名单等。

我现在准备运行一些测试,看看我的工作是否得到回报。 我想我只需下载一些脚本小子应用程序来运行测试。 我找不到任何东西,而我能找到的那些都是坏的或二进制的且不可配置的。

我将有一个循环生成的地址列表。

我想将 $address 作为参数并执行以下操作:

telnet myserver.com 25 你好 some-string.com 邮件来自:[电子邮件受保护] 接收到:$address 退出

,我需要测试一些事情,例如,如果我启用灰名单,我想让脚本失败,因为这是我的第一个对策。 我想在这种情况下,我只会有 telnet 超时?

  • helo 应该返回一个以 220 开头的代码字符串,这与我进行此测试所需的准确度差不多。

  • mail from 应返回 250,或者查找 OK 就足够了

  • rctp to 应返回 250 或 Ok,有时,当我发送有效用户时,但大多数情况下有时我会发送一个错误的地址,所以我寻找没有 250 或 OK。

  • 最后,我将发送退出

我无法在交互式情况下获得条件和日志记录。 我查看了 expect 但无法让它工作。

到目前为止我的代码:

echo -e "helo foo\nmail from: foo.... | telnet example.com 25 | grep -i blah 

这没有按预期执行。

我可以做什么来实现我的目标?

I need to make a large set of tests in telnet. I am working on some ways to auto detect dictionary attacks on our email server, and then throttle them back, or blacklist them etc.

I am now ready to run some tests and see if my work pays off. I figured I would just download some script kiddy app to run the tests. I can not find any and those I can are bad or binary and non configurable.

I will have a list of addresses I generate in a loop.

I want to take $address as an argument and do this:

telnet myserver.com 25
helo some-string.com
mail from: [email protected]
rcpt to: $address
quit

Within that, I need to test a few things, such as, if I enable greylisting, I want to fail the script, as that is my first countermeasure. I suppose in that case, I would just have telnet timeout?

  • helo should return a code string starting with 220, that is about as accurate as I need to make this test.

  • mail from should return 250, or looking for OK would suffice

  • rctp to should return 250 or Ok sometimes, when I send in a valid user, but most of the time I will send in a bad address, so I look for the absence of 250 or OK.

  • Finally, I will send in a quit.

I am not able to get conditions and logging to happen within an interactive situation. I looked at expect but could not get it to work.

My code so far:

echo -e "helo foo\nmail from: foo.... | telnet example.com 25 | grep -i blah 

This did not perform as expected.

What can I do to accomplish my goal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

余生共白头 2024-07-22 08:30:22

尝试 netcat: http://netcat.sourceforge.net/

它可以让您发送和接收数据一个插座。 telnet 不是您想要的 - 它是为了交互式使用。

Try netcat: http://netcat.sourceforge.net/

It'll let you send and receive data on a socket. telnet isn't what you want - it's for interactive use.

孤君无依 2024-07-22 08:30:22

Expect 围绕 netcat(而不是 telnet)可能是最好的初始选择。
但是,如果你真的需要这个,我会使用 perl。 有适用于它的 SMTP 客户端库。

expect wrapped around netcat (instead of telnet) is probably the best initial bet.
But, if you really need to this, I would use perl. There are SMTP client libraries for it.

氛圍 2024-07-22 08:30:22

我很惊讶 Expect 没有为您做这件事,因为它就是为这类事情而编写的。

Perl 在某些方面更简单并且可以完成这样的工作。 但使用 Perl,你就不用费心 Telnet 了,你可以直接打开端口 25。

如果你真的想锻炼你的服务器,请获取 Siege 的源代码并将其修改为对话SMTP 而不是 HTTP。 这是我最喜欢的测试 Apache 性能的工具,我确信用它测试 Sendmail 不会太难。

I'm surprised that Expect didn't do it for you since it's written for just these kinds of things.

Perl is simpler in some ways and can get a job like this done. But with Perl, you won't bother with Telnet, you can instead open port 25 directly.

If you really want to exercise your server get the source for Siege and modify it to talk SMTP instead of HTTP. That was my favorite tool for testing Apache performance and I'm sure it wouldn't be too hard to make it test Sendmail.

原谅我要高飞 2024-07-22 08:30:22

您可以使用 Bash 语法来实现此目的,例如,

exec {stream}<>/dev/tcp/example.com/80
printf "GET / HTTP/1.1\nHost: example.com\nConnection: close\n\n" >&${stream}
grep Example <&${stream}

这是另一个语法示例,它从 memcached 转储键列表

exec {memcache}<>/dev/tcp/localhost/11211; printf "stats items\nquit\n" >&${memcache}; cat <&${memcache}

You can use Bash syntax for that, e.g.

exec {stream}<>/dev/tcp/example.com/80
printf "GET / HTTP/1.1\nHost: example.com\nConnection: close\n\n" >&${stream}
grep Example <&${stream}

Here is another syntax example which dumps list of keys from memcached:

exec {memcache}<>/dev/tcp/localhost/11211; printf "stats items\nquit\n" >&${memcache}; cat <&${memcache}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文