🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.privacy.anon-server
Article #182633

Stealth, software useful for intermittently-connected site

#182633
From: StealthMonger
Date: Wed, 09 Mar 2005 10:36
356 lines
14950 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Last modified: Wed Mar  9 02:29:42 UTC 2005

[For documentation, see STEALTH essay of 2005 March 8.]

PROGRAMS USEFUL FOR AN INTERMITTENTLY CONNECTED SITE SENDING STRAIGHT
TO A.A.M WITHOUT REMAILERS

outbeat.intermittent       Shell script maintains an output heartbeat
                           of traffic, suitable for an intermittently-
                           connected site.

make_outbeat_cover         Shell script generates a piece of outbound
                           cover traffic.

mail_listener              Moves live outbound traffic to the queue
                           atomically.

pon_if                     Coordinates asynchronous demands for
                           bringing up a modem connection.

poff_if                    Companion to pon_if.

To whatever extent I am free to do so, I declare this software to be
under GPL.  Here it is:


- ----------------------------8<----------------------- outbeat.intermittent
#!/bin/sh

# SYNOPSIS

#    outbeat

# DESCRIPTION

# outbeat : "Output Heartbeat" or "Output Drum-beat"

# Maintain a rigidly periodic sequence of mailings or postings, using
# dummy articles when there are no live ones to send.  The live and
# dummy articles are supposed to be indistinguishable except to an
# intended recipient who has the correct decryption keys.  The effect
# is to conceal live traffic in an ongoing stream of cover traffic, so
# that an observer cannot determine when or how much live traffic is
# being sent.

# The frequency of the output mails is determined by the "mail
# period", which can be set by the user.  Once established, it defines
# an unending sequence of time-slots into the future, to each of which
# will be assigned a mail.  If sending is interrupted for a time,
# perhaps because the Internet connection or the computer itself is
# down, the actual sending frequency is increased when the system
# comes back up, until synchrony is reestablished.  Frequency during
# such catch-up phases is determined by the "catch-up period", which
# is also a user-controlled parameter.

# Notes on choosing the mail period and the catch-up period.  The mail
# period should be short enough to accommodate all live traffic into
# the foreseeable future without unduly delaying any particular mail;
# however, it should be no shorter, to avoid accusations of abuse.
# The catch-up period has to be shorter, and is some compromise between
# making sure catch-up actually occurs often during up-times on the one
# hand, and being open to charges of abuse of the system on the other.

# outbeat is intended to be left running at all times.  However, it is
# reasonably tolerant of restarts, as would be required for example if
# the computer is taken down and rebooted.  It spends most of its time
# asleep.

# outbeat state is maintained in a directory $DIR, which must be
# writable by the user.  On first-ever invocation, outbeat creates the
# necessary files and directories under $DIR.  They are:

# next_slot A small file which always holds the absolute (since epoch)
#           minute-count at which the next unsent mail should be or
#           should have been sent.

# urgent    A Maildir-style mail directory for urgent outgoing mail.

# normal    A Maildir-style mail directory for routine outgoing mail.

# cover     A Maildir-style mail directory for outgoing cover mail.

# See Bernstein's qmail documentation for a description of Maildir
# directories.  A Maildir has subdirectories tmp, new, and cur.  New
# articles can be constructed in tmp and moved to new when completed.
# Because all components of a Maildir are required to be in the same
# file system, such a move is an atomic operation, eliminating mail
# loss or duplication which can result from race conditions.

# urgent, normal, and cover form a priority queue for outgoing mail.
# The user constructs an article in normal/tmp/ or urgent/tmp/, then
# moves it to normal/new/ or urgent/new/.  cover/tmp and cover/new are
# used in a similar way for cover traffic, except that whenever
# cover/new goes empty, this script calls a user-supplied program
# MAKE_COVER, which is supposed to create a new piece of cover traffic
# for use next time it's needed.

# Each time a mail is to be sent, outbeat selects a highest-priority,
# oldest article, sends it, and moves it to the cover/cur directory
# (renaming it to usually prevent clobbering a previous entry there).
# Sent articles all go to the same directory so as to erase record of
# which are live and which are dummy.  (normal/cur and urgent/cur are
# therefore not used, and need not actually exist.)  The user should
# delete old articles from cover/cur/ from time to time, so they don't
# pile up indefinitely.  (They are useful for monitoring and debugging
# outbeat operation.)  The sent article is also touch(1)ed to erase
# its original modification and access times, further obscuring its
# origin.  Note the rename erases the original creation time.

# An article deposited in */new should be complete with headers.  It
# is sent verbatim as standard input to "/usr/lib/sendmail -t", which
# should be implemented even in systems using other than sendmail as
# the MTA (true for example for qmail and smail and exim).

# This version of outbeat is tailored for use on a machine whose
# Internet connection is intermittent and on-demand.  In order to
# maintain an autonomous output pattern uncorrelated with live
# traffic, this script brings up the Internet connection when needed.
# But because other users of the machine may asynchronously generate
# demand for a connection, there are global scripts pon-if and poff-if
# to bring it up and take it down, through which all potential users,
# including this outbeat, must coordinate their demands.

# Directory where it all happens
DIR=/var/lib/outbeat
# Time in minutes between mails:
MAIL_PERIOD=120
# Time in minutes between mails during catch-up:
CATCHUP_PERIOD=60
# Program to generate cover traffic
MAKE_COVER=/var/sys/bin/make_outbeat_cover

# Thanks to D. J. Bernstein:
maildirmake () {
  mkdir -p -m 0700 $1/tmp
  mkdir -p -m 0700 $1/new
  mkdir -p -m 0700 $1/cur
  }

mkdir -p $DIR
cd $DIR

# Begin one-time initialization

if [ ! -f next_slot ] ; then
   # Current time in minutes since 1970 Jan 1 00:00 :
   echo $(date +%s) 60 / p | dc > next_slot
   # Make required directories :
   maildirmake cover
   maildirmake normal
   maildirmake urgent
   fi

# End one-time initialization

# The loop is organized to do the right thing during normal, routine
# operation, but also to be somewhat graceful in case of one or more
# restarts during one sleep interval (as might occur while performing
# unrelated system maintenance) and for the one-time initialization.

# Arrange for immediate send unless next_slot is in the future.  If
# this is a restart after a brief interruption, this could crowd
# multiple sends into less than one CATCHUP_PERIOD.  Tough.

WAKEUP_TIME=$(cat next_slot)

while true; do

   # Be sure that there's some cover traffic if needed:
   if [ "$(ls cover/new/* 2>/dev/null)" == "" ] ; then
      $MAKE_COVER $DIR
      fi

   SLEEPTIME=$(echo $WAKEUP_TIME 60 '*' $(date +%s) - p | dc)
   if (( $SLEEPTIME > 0 )) ; then sleep $SLEEPTIME ; fi

   # NB: Elapsed real time between here and the "sendmail" invocation
   # below is world-visible, and should not be allowed to depend
   # significantly on whether the mail to be sent is live or dummy.

   # Minutes since 1970 Jan 1 00:00 :
   NOW=$(echo $(date +%s) 60 / p | dc)
   NEXT_SLOT=$(cat next_slot)

   # Bring up the modem link if necessary..  (uses our  own pon)
   pon-if outbeat
   # Give it a while to come up..
   sleep 120

   if [ -e /var/lock/LCK..ttyS1 ] ; then

      # Select the highest priority, oldest mail for sending..
      SENDING=$(echo $(ls -tr urgent/new/* 2>/dev/null) \
                     $(ls -tr normal/new/* 2>/dev/null) \
                     $(ls -tr  cover/new/* 2>/dev/null) \
                   | cut -d ' ' -f1)

      # (Does Allman's sendmail return a useful exit code?  The bat book
      # doesn't say.  exim does, when sendmail is emulated that way.)
      if ( /usr/lib/sendmail -t < $SENDING ) ; then

         # Successfully sent.  Move it out of the way to be manually
         # reaped later, changing its name to usually avoid collision.
         # Sent mails from all queues are merged into cover/cur/ to erase
         # record of which are live, which are dummy.  Also they are
         # touched to erase original modification and access times (the
         # mv takes care of the creation time).
         touch $SENDING
         mv $SENDING cover/cur/$NOW
         fi

      # After a send, the next_slot time is advanced by one period
      # regardless of whether the send was on time:

      NEXT_SLOT=$(( $NEXT_SLOT + $MAIL_PERIOD ))
      echo $NEXT_SLOT > next_slot

      # Opportunisticly perform other network activity
      pon-if pull-aam
      ~/bin/pull-aam &
      pon-if run-mail-queue
      ~/bin/run-mail-queue &

   fi

   poff-if outbeat

   # The time of our next wake-up call:
   if (( $NEXT_SLOT - $NOW < $CATCHUP_PERIOD )) ; then
      WAKEUP_TIME=$(( $NOW + $CATCHUP_PERIOD )) ; else
      WAKEUP_TIME=$NEXT_SLOT
      fi

done

# Implementation notes: Times are expressed in minutes partly because
# this was initially conceived as an "at" script, which uses minutes,
# and partly because seconds-counts since epoch are large enough to
# stress long-integer limitations in some installations.

# "at" was not used because it insists on writing to stderr no matter
# what, and because it doesn't accept simple seconds-since-epoch as
# the time the job should be run.  Stupid translations would be
# required from tick-counts to "civil" time notations, just so at's
# algorithm could apply the reverse translation back to tick-counts
# again.  So instead, one perpetual process is used, which spends most
# of its time sleep(1)ing.

# A down-side of this implementation is that some way has to be found
# to automatically start the job at boot time.  (But to prevent floods
# of outbound mail it should only run while connected to the Internet,
# so it could be started from ip-up.)

# Modified 2004 Nov 11: added "touch $SENDING" to erase original
# create and access times; cleaned up documentation a bit.

- ---------------------------->8------------------------------------------
- ----------------------------8<----------------------- make_outbeat_cover
#!/bin/sh

# Generate a piece of cover traffic ready to feed to sendmail -t

# IMPORTANT: Modify the size distribution to match your own live
# outbound mail statistics!
SIZESCALE=3333
FILE=/var/lib/outbeat/cover/tmp/$(date +%s).$$

echo To: mail2news@dizum.com > $FILE
echo Newsgroups: alt.anonymous.messages >> $FILE
echo -n Subject:\  >> $FILE
esubbf $(random-key) $(random-key) >> $FILE
echo -e \\n >> $FILE
mknod random.key p
openssl rand -base64 30 | tr -d "\n" > random.key &
openssl rand $( echo " ( l ( 16777216 ) \
 - l ( $( openssl rand 3 | od -tu4 | head -1 | cut -c9- ) + 1 ) ) \
 * $SIZESCALE " | bc -l | sed 's/\(^.*\)\..*$/\1/' ) \
 | gpg -c -a --passphrase-fd 3 3<random.key --batch --cipher-algo 3DES \
 | sed 2,3d >> $FILE
rm random.key
mv $FILE /var/lib/outbeat/cover/new/

- ---------------------------->8------------------------------------------
- ----------------------------8<----------------------- mail-listener
#!/bin/sh

# Listen for outbound mail and queue it for outbeat

while true; do
   nc -l -p 1212 < /dev/null > /var/lib/outbeat/normal/tmp/$(date +%s).$$
   # Atomic operation, so outbeat never gets a partial file:
   mv /var/lib/outbeat/normal/tmp/* /var/lib/outbeat/normal/new/
done
- ---------------------------->8------------------------------------------

Demand for an Internet connection may arise asynchronously from at
least outbeat and an interactive user.  It may be difficult for either
to be sure the other's demand has passed.  So each current user has a
token in a directory /var/lib/modem-users in the form of a file there.
When the tokens are all gone, the connection may be brought down.
- ----------------------------8<----------------------- pon-if #!/bin/sh

# SYNOPSIS
#       pon-if <id>

# DESCRIPTION
#       Gain exclusive access to directory /var/lib/modem-users, then
#       if the modem link is down remove possible (stale) files and
#       bring it up, and finally add a file <id>.

# SEE ALSO /usr/local/bin/poff-if

lockfile /var/lock/modem-users.lock

if [ ! -e /var/lock/LCK..ttyS1 ] ; then
    rm -f /var/lib/modem-users/*
    /usr/sbin/pppd call provider
fi

touch /var/lib/modem-users/$1

rm -f /var/lock/modem-users.lock
- ---------------------------->8------------------------------------------
- ----------------------------8<----------------------- poff-if
#!/bin/sh

# SYNOPSIS
#       poff-if <id>

# DESCRIPTION
#       Gain exclusive access to directory /var/lib/modem-users, then
#       remove any file <id> and, if this leaves the directory empty,
#       take down the modem link.

# SEE ALSO /usr/local/bin/pon-if

lockfile /var/lock/modem-users.lock

rm -f /var/lib/modem-users/$1
if [ -z "$(ls /var/lib/modem-users)" ] ; then killall -q -w pppd ; fi

rm -f /var/lock/modem-users.lock
- ---------------------------->8------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQFCLl/bDkU5rhlDCl4RAlTHAKDE1LRRoyb7IK7pBG1ZR/c3mEFJcQCfaxwu
kjnnbxccXU2ahX3k6q6eR4Y=
=lYQq
-----END PGP SIGNATURE-----
Technical Details
Message-ID: <200503091036.j29AaLFw011236@marco.aarg.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!news.wiretrip.org!news.dizum.com!sewer-output!mail2news

Show Full Headers
Complete Article Headers
Message-ID: <200503091036.j29AaLFw011236@marco.aarg.net>
Subject: Stealth, software useful for intermittently-connected site
Date: Wed, 9 Mar 2005 02:36:21 -0800
From: StealthMonger <Use-Author-Supplied-Address-Header@[127.1]>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!news.wiretrip.org!news.dizum.com!sewer-output!mail2news
Author-Supplied-Address: StealthMonger <AT> hod <DOT> aarg <DOT> net
Newsgroups: alt.privacy.anon-server
X-Virus-Status: Clean
Mail-To-News-Contact: abuse@dizum.com
Organization: mail2news@dizum.com