Article View: news.software.nntp
Article #51982Re: Canceling articles from within a newsreader
From: Damien
Date: Sun, 22 Apr 2001 19:30
Date: Sun, 22 Apr 2001 19:30
229 lines
7885 bytes
7885 bytes
On Thu, 19 Apr 2001 22:32:17 -0500, Mach <mach@xganon.com> wrote:
>
> >> Mach:
> >>
> >> If you happen to run INND, you can use the program at the bottom of
> >> this article to (locally) cancel articles from within a news
> >> reader like Messenger.
> > not-a-real-address:
> >
> > cool. now everyone knows how to cancel articles on your server, i.e.,
> > no authenticate, and it's got a couple of spiffy holes just waiting to
> > let folks crack your newsadmin account.
>
>
> Will you help me raise newskill's version above 0.21?
>
> Is it possible to use a cookie to authenticate email from Messenger?
>
> Can you use procmail to secure it?
>
> What security holes do you see?
> It attacks hip crime floods like nitric acid.
I don't see how this is useful for flood. It involves dealing with
the messages individually.
In general though, I don't like this approach at all Mach. First off,
it's a setuid news admin program available for anyone in the run.
Never mind the fact that it has zero authentication, that can be
fixed. But there really is no need to let Joe Internet have access to
it, when you can make it only available to local users.
That, and it's written in C++. I really can't stand C/C++ and only
use it when I have too. With that as a disclaimer, this program does
two things, finds the Message-ID's in the the body of an email, and
runs "ctlinnd cancel" on them. Perl is much better suited for this,
making the whole thing easier to read and write aloowing you to focus
on avoiding the security holes not-a-vaild-address pointed out.
> ________________________________cut_________________________________
[snip unimportant stuff]
> int main(int argc, char **argv) {
> int c;
> char cmdString[MAXLINELEN + 38];
> char msgIDHeader[] = {"Message-ID: "};
> char nl[MAXLINELEN];
> int nlLen;
> int returnVal;
>
> OptionAction = FALSE;
> OptionDebug = FALSE;
>
> while ((c = getopt(argc, argv, "ad")) != EOF) {
> switch (c) {
> case 'a':
> OptionAction = TRUE;
> break;
> case 'd':
> #ifdef DEBUG
> OptionDebug = TRUE;
> #endif
> break;
> #endif
> break;
> }
> }
Interesting. . . your action switch does nothing.
> if (OptionAction) {
> openlog ("newskill", LOG_NDELAY, LOG_LOCAL7);
> } else {
> openlog ("newskill", LOG_NDELAY, LOG_LOCAL7);
> }
This is just ugly. I have two words for you, "regular" and
"expressions".
> /*
> * find sendmail's Message-ID (the very first Message-ID)
> * and ignore it
> */
> for (;;) {
> if (fgets(nl, sizeof nl, stdin) == NULL) {
> return -1;
> }
> if (strncmp(msgIDHeader, nl, sizeof msgIDHeader - 1) == 0) {
> /* we found the first Message-ID, break out of the for loop */
> break;
> }
> }
>
> /*
> * invoke ctlinnd cancel against all of the remaining
> * Message-IDs, attached to the email.
> */
> for (;;) {
> if (fgets(nl, sizeof nl, stdin) == NULL) {
> break;
> }
> if (strncmp(msgIDHeader, nl, sizeof msgIDHeader - 1) == 0) {
> nlLen = strlen(nl);
> if (nl[nlLen - 1] == '\n') { /* remove new line */
> nl[nlLen - 1] = 0;
> }
This is probably one of the holes not-a-vaild-address was talking
about. What keeps me from using this as a message id:
"some-random-message-id'; nc -l -p 33173 > /bin/sh;'"
> sprintf(cmdString, "/usr/local/news/bin/ctlinnd cancel '%s'", &(nl[sizeofmsgIDHeader - 1]));
> MESSAGE(cmdString);
> returnVal = system(cmdString);
> if (returnVal == -1) {
> syslog (LOG_ERR, "Problem invoking: %s", cmdString);
> }
> }
> }
>
> return 0;
> }
Here's a perl version of the same program. It's untested, but it
should give you an idea of why C/C++ is evil, and unsuited for your
purpose.
----newskill.pl---
#!/usr/bin/perl -wT
use strict;
##############################
#
# newskill.pl
#
# Cancels all news messages in the body of an email
#
# Usage: pipe the email in to the program
#
# Bugs and Limitations:
# doesn't work if the message-id header of the offending email
# covers more than one line. Multi-line headers are legal
# according to rfc1036 but exceedingly rare for message-id headers
#
# assumes the email has exactly one message-id header
##############################
# path to ctlind
my $ctlind = "/usr/local/news/bin/ctlinnd";
# path to logfile
my $logfile = "/dev/null";
my $found_mail_message_id = "";
open(LOGFILE, ">>$logfile");
while(<>){
# is this line a message-id header?
if(m/Message-ID:\ <(\W+?)>/x){
# if we haven't found the mail id yet
if(! $found_mail_message_id){
$found_mail_message_id = "1"; # we have now
# otherwise, this is a message-id of a news message
}else{
# so cancel it
my $return_val = system($ctlinnd, "cancel", $1);
# and log if anything went wrong
if($return_val > 0){ print LOGFILE "Error cancelling $1\n"; }
}
}
}
------------------
A better approach probably would have been to keep reading until we
get to a blank line. After that we would know we are in the body of
the message.
But I wouldn't use this either for reasons given above. slrn, my
nesreader of choice, has the ability to pipe articles to a program.
So I would have put newskill in /usr/local/bin/, setuid to the news
admin and written it something like this:
----newskill.pl---
#!/usr/bin/perl -wT
use strict;
##############################
#
# newskill.pl
#
# Cancels the news messages it recieves on STDIN
#
# Bugs and Limitations:
# doesn't work if the message-id header of the offending email
# covers more than one line. Multi-line headers are legal
# according to rfc1036 but exceedingly rare for message-id headers
##############################
# path to ctlind
my $ctlind = "/usr/local/news/bin/ctlinnd";
while(<>){
# find the message-id
if(m/$Message-ID:\ <(\W+?)>/x){
# and cancel it
my $return_val = system($ctlinnd, "cancel", $1);
# if anything went wrong, tell the user
if($return_val > 0){ print "Error cancelling $1\n"; }
# all done
exit $return_val;
}
}
# no message id found, tell user
print "Cannot cancel article, no Message-ID header found.\n"
exit 8;
------------------
If the box you use to read news is different from your server, you can
probably use some ssh -c magic to make this work.
Unfortunatly I couldn't find a way to bind a key in slrn to pipe and
article to a particular program. Maybe I'll put that in their
wish-list box.
HTH.
--Damien
Technical Details
Message-ID:
<3ae33166$0$1917$b45e6eb0@senator-bedfellow.mit.edu>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!newsfeed.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mailReferences:
<ILAD6.44$8n2.28999@dfiatx1-snr1.gtei.net> <200104191703.MAA01793@www.xganon.com> <tdv6gcjos0g0f8@news.supernews.com> <200104200332.WAA31099@www.xganon.com>Show Full Headers
Complete Article Headers
Message-ID: <3ae33166$0$1917$b45e6eb0@senator-bedfellow.mit.edu> Subject: Re: Canceling articles from within a newsreader Date: Sun, 22 Apr 2001 19:30:47 +0000 From: damien@damien.mit.edu.munge (Damien) References: <ILAD6.44$8n2.28999@dfiatx1-snr1.gtei.net> <200104191703.MAA01793@www.xganon.com> <tdv6gcjos0g0f8@news.supernews.com> <200104200332.WAA31099@www.xganon.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!newsfeed.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail Newsgroups: alt.hackers.malicious,news.software.nntp Reply-To: damien@damien.mit.edu.munge User-Agent: slrn/0.9.7.0 (Linux) Lines: 228 NNTP-Posting-Host: DAMIEN.MIT.EDU X-Trace: 987967847 senator-bedfellow.mit.edu 1917 18.239.2.147