[Exchange2K] event sink gebruiken om spam te verplaatsen

Pagina: 1
Acties:
  • 95 views sinds 30-01-2008

  • markjuh
  • Registratie: Juli 2000
  • Laatst online: 16-11-2025
Op dit moment ben ik wat aan het proberen met event sink. Wat ik wil is het volgende. Door de provider waar we batch SMTP draaien wordt spam gecontroleerd en zodra dit spam is wordt er in de header van de mail toegevoegd X-Spam-Level: ***** waar het aantal sterretjes staat voor het niveau van spam. Nu wil ik dat alles waar 4 sterren of meer staan in de header dat deze verplaatst wordt in een public folder die we voor het gemak dan maar even spam noemen. Ik ben wat aan het vogelen met event sink maar kom er nog niet echt uit.

voorbeeldscript van de MS site:
<SCRIPT LANGUAGE="VBScript">

Sub IEventIsCacheable_IsCacheable()
'To implement the interface, and return S_OK implicitly
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
Dim envFlds
Dim colAttachs
Dim iFound
Set envFlds = Msg.EnvelopeFields

If Msg.Subject = "" Or Len(Msg.Subject) < 5 Then
iFound = 0
Else
iFound = Instr(1, Msg.Subject, "VIRUS", 1) ' First position of the word VIRUS
End If

'Check whether the message contains a VBS attachment
Set colAttachs = Msg.Attachments
For Each oAttach in colAttachs
If InStrRev(oAttach.FileName, ".vbs",-1, 1) = (Len(oAttach.FileName)-3) Then
iFound = 1
End If
Next

If iFound > 0 Then
'Do not deliver, place message in the Badmail directory.
envFlds ("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus") = 3
envFlds.Update 'Commit the changes of the message status 'Skip remain event sinks
EventStatus = 1
End If
End Sub

</SCRIPT>
Nu weet ik dat ik zou moeten checken met Msg.Headers ipv Msg.Subject . Maar het wil niet lukken. en in dit script wordt het verplaatst in de badmail en dit wil ik ook niet. Heb toch al een behoorlijke tijd gezocht maar kom er niet uit.

Wie kan mij helpen?

  • Grolsch
  • Registratie: Maart 2003
  • Laatst online: 17:47
wil je een mooi of een eerlijk antwoord :?

Om eerlijk te zijn ben ik er ook wel eens mee bezig geweest, maar het is gewoon een drama om met exchange met die event sinks te werken.
Investeer een paar € in een fatsoenlijke SPAM filter.
Neem bijvoorbeeld GFI Mailessentials ( http://www.gfi.com/mes/ )

PVOUPUT - 13.400WP - Twente


  • markjuh
  • Registratie: Juli 2000
  • Laatst online: 16-11-2025
Ik ken GFI. Maar dit is voor een klant die geen spam pakket wil. GFI is een heerlijke oplossing. Als ik de mogelijkheid had dan had ik dit direct gebruikt. Maar ze willen het op deze manier oplossen.

Ik kom er gewoon niet verder mee. En allerlei keywords invullen en daarop filteren wil ik ook niet. Omdat de header van de mail getagged wordt door de provider zou ik op zich hier iets moois mee kunnen doen maar ik krijg het niet voor elkaar.

  • StevenK
  • Registratie: Februari 2001
  • Laatst online: 18-02 20:39
Ik draai (thuis) al een hele tijd een eventsink die alle mail door spamassassin en door Clam heen haalt.

Bevalt mij uitstekend.

Is gebaseerd op een script wat ik ergens van Internet heb gehaald (De hier aangehaalde 'Eric Smtih' en daarna aangepast heb, o..a vanwege logging.
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<SCRIPT LANGUAGE="VBSCRIPT">
'------------------------------------------------------------------------------
' NAME:         SpamFilter.vbs
' VERSION:      0.1 - 6/18/03
' DESCRIPTION:  Grabs each message coming into the STMP service and dumps it out
'                   to a file. Then executes a spamassassin bat file on it. Then
'                   scans that file to see if it is spam or not, and 
'                   acts accordingly. ("accordingly" having several meanings,
'                   depending on what you want done to your Spam)
'
' NOTES:        This will be slowish - so if you have a lot of users, this 
'                   probably isn't your best option.
'               This will grab mail coming from outside of your Exchange server.
'               We don't get Spam from inside of our Exchange server - if you do
'                   then you probably have larger issues to deal with than just
'                   this script.
'
' TODO:         Reports/charts, add the local recipient's address and/or name to
'                   the filename so that they are easier to lookup upon complaint
'------------------------------------------------------------------------------

' Declare Windows 2000/2003 SMTP Transport Event Sink constants
Const cdoRunNextSink = 0
Const cdoSkipRemainingSinks = 1
Const cdoStatAbortDelivery = 2
Const cdoStatBadMail = 3

' Set to false if you do not want to keep any messages in the Windows SMTP BADMAIL folder
Const ENABLE_BADMAIL = False
'set this if you want messages to be flagged as spam instead of sent to badmail or killed
Const ENABLE_FLAG_MESSAGE = False

' Declare ADO constants
Const adSaveCreateOverWrite = 2

' paths to folders we will be using
Const TEST_PATH = "d:\spamfiltervbs\test\"
Const SPAM_PATH = "d:\spamfiltervbs\files\spam\"
Const NONSPAM_PATH = "d:\spamfiltervbs\files\goed\"


Sub ISMTPOnArrival_OnArrival(ByVal objMessage, EventStatus)

    'Start up Error Checking (so that we can promptly ignore it)
    On Error Resume Next
    'on error goto :errhandler

    ' Declare variables
    Dim strTestEmail
    Dim objFields              
    Dim objStream           
    Dim iCount 
    Dim listRnd 
    Dim iRnd 
    Dim strRandom
    Dim oShell
    Dim objFileSystem
    Dim strMessage
    Dim ts    
    Dim f
Dim myitem
dim i
  Dim fs
  Set fs = CreateObject("Scripting.FileSystemObject")
  Dim file, file2
thisdate=now()
thisyear = year(thisdate)
thismonth = right("0" & month(thisdate),2)
thisday = right("0" & day(thisdate),2)
mytoday = thisyear & thismonth & thisday
set file2 = fs.opentextfile("d:\spamfiltervbs\error.log", 8 , true)
Set file = fs.OpenTextFile("d:\spamfiltervbs\logs\spamfiltervbs " & mytoday & ".log", 8, True )
total=0
virus=0
spam=0
pass=0
'
if fs.FileExists("d:\spamfiltervbs\counters\" & mytoday & ".txt") then
    Set f3 = fs.opentextfile("d:\spamfiltervbs\counters\" & mytoday & ".txt")
    sendstats=false
    regel = f3.readline
    total=right(regel,len(regel)-instr(regel,"="))
    regel = f3.readline
    virus=right(regel,len(regel)-instr(regel,"="))
    regel = f3.readline
    spam=right(regel,len(regel)-instr(regel,"="))
    regel = f3.readline
    pass=right(regel,len(regel)-instr(regel,"="))
    f3.close
else
    'file does not exist; e-mail old file, if any
    sendstats=true
end if
total=total+1
    file.write date() & "," & time() & ","
    file.write "from: " & objMessage.from & ","

    ' Get fields collection of message
    Set objFields = objMessage.EnvelopeFields   

    ' Process message
    With objMessage

        ' Get message as stream
        Set objStream = .GetStream
'check for german virus

        ' Save message as stream to file 
        objStream.SaveToFile (TEST_PATH & "spamtestin.txt"), adSaveCreateOverWrite
    End With

    'spamtest file now exists, so we should now run spamassassin against it and have it output a file
    Set oShell = CreateObject("WScript.Shell")
'Run clamscan
    oShell.Run "d:\spamfiltervbs\mailscan.bat", 0, True
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
dim f2, ts2, strmessage2
    'Open the virusscan result file
    Set f2 = objFileSystem.GetFile(TEST_PATH & "scanresult.txt")
    Set ts2 = f2.OpenAsTextStream(1,-2)
    strMessage2 = ts2.ReadAll
    ts2.Close
'Check for the ': OK' entry
if instr(1,strMessage2, ": OK", 1) then

'No virus found
    oShell.Run "d:\spamfiltervbs\exchange_spam_check.bat", 0, True
    'now open up the spamtestout.txt file and see if that is spam (see if it contains "X-Spam-Status: Yes"
    'if it is spam, then copy spamtestin.txt to a randomly named text file in the SPAM_PATH
    'if it is not spam, then copy spamtestin.txt to a randomly named text file in the NONSPAM_PATH
    'then later run bat scripts to learn on those directories, and then del the files in there after learning

    'open up the file
    Set f = objFileSystem.GetFile(TEST_PATH & "spamtestout.txt")
    Set ts = f.OpenAsTextStream(1,-2)
    strMessage = ts.ReadAll
    ts.Close

    pos = instr(strMessage,"score=" )
    pos2 = instr(mid(strmessage,pos+6,25),"required=")
    file.write (mid(strmessage,pos+6,pos2-1)) & ","
'create a random filename
    randomize     
    iCount = 1        
    DO        
        'get random number b/w 48 & 122 (0 - Z)
        iRnd = int(75 * rnd + 48)        
        'limit string to 0-9, a-z, A-Z
        if (iRnd < 57 OR iRnd > 65) AND (iRnd < 90 OR iRnd > 97) then
             listRnd = listRnd & chr(iRnd)
             iCount = iCount + 1
        END IF        
    LOOP UNTIL iCount = 21

    'make it a little more readable
    strRandom = mid(listRnd,1,5) & mid(listRnd,6,5) & mid(listRnd,11,5) & mid(listRnd,16,5)          

    'check to see if it is spam
    If InStr(1, strMessage, "X-Spam-Status: Yes", 1) Then
file.write "SPAM" & vbcrlf
spam=spam+1
        'if in here, then it is Spam
        'write it to the spam dir
        objStream.SaveToFile (SPAM_PATH & strRandom & ".txt"), adSaveCreateOverWrite
    Set file6 = fs.OpenTextFile(SPAM_PATH & "report\" & strRandom & ".out.txt", 8, True )
    file6.write strMessage
    file6.close
        'since it is spam, we now need to flag it, or move it to the badmail, or just let it die
        'if we are going to badmail it, or let it die, then we can set the event status so that it
        'does not run any more Sinks on it
        If ENABLE_FLAG_MESSAGE Then
            'if in here, then we will add a flag to the message subject
            objMessage.Subject = "*****SPAM*****" & objMessage.Subject
            objMessage.DataSource.Save
            'the message is still getting sent to the user, so keep checking sinks
            EventStatus = cdoRunNextSink
        Else
            'if in here, then we are either sending it to badmail, or just letting it die
            If ENABLE_BADMAIL Then
                'if in here, then we will send the message to badmail
                objFields.Item("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus").Value = cdoStatBadMail
                objFields.Update
            Else
                'if in here, then we will just let the message die
                objFields.Item("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus").Value = cdoStatAbortDelivery
                objFields.Update
            End If
            'since we are in here, the message isn't going to go to the user anymore, so 
            'we can stop running any more sinks on it
            EventStatus = cdoSkipRemainingSinks
        End If
    Else
file.write "No SPAM" & vbcrlf
pass=pass+1
        'if in here, then it is not Spam (Ham)
        'write it to the non spam dir
        objStream.SaveToFile (NONSPAM_PATH & strRandom & ".txt"), adSaveCreateOverWrite
    Set file6 = fs.OpenTextFile(NONSPAM_PATH & "report\" & strRandom & ".out.txt", 8, True )
    file6.write strMessage
    file6.close

        'since it is not spam, we will just leave it alone from here out and it will get to the sender
        EventStatus = cdoRunNextSink
    End If
else
    'Virus found
        virus=virus+1
        file.write "0,VIRUS" & vbcrlf
                objFields.Item("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus").Value = cdoStatAbortDelivery
                objFields.Update
end if

    ' Clean up the mess we have made
  file.Close
    Set objStream = Nothing
    Set objFields = Nothing
    Set oShell = Nothing
    Set f = Nothing
    Set ts = Nothing
if sendstats=true then
thisdate=now()-1
thisyear = year(thisdate)
thismonth = right("0" & month(thisdate),2)
thisday = right("0" & day(thisdate),2)
myyesterday = thisyear & thismonth & thisday
total=0
virus=0
spam=0
pass=0
    Set objMessage = CreateObject("CDO.Message") 
    objMessage.Subject = "SPAM filter statistics " & myyesterday
    objMessage.Sender = """Spamfilter DC1"" <spamfilter@domein.nl>" 
    objMessage.To = "steven@domein.nl" 
    Set f5 = objFileSystem.GetFile("d:\spamfiltervbs\counters\" & myyesterday & ".txt")
    Set ts2 = f5.OpenAsTextStream(1,-2)
    objMessage.TextBody = ts2.ReadAll   
    ts2.Close
    objMessage.Send
end if
Set file4 = fs.OpenTextFile("d:\spamfiltervbs\counters\"  & mytoday & ".txt", 2, True )
file4.write "total=" & total & vbcrlf
file4.write "virus=" & virus & vbcrlf
file4.write "spam=" & spam & vbcrlf
file4.write "pass=" & pass & vbcrlf
file4.close
    set fs = nothing
    Set objFileSystem = Nothing
file2.close
End Sub
</SCRIPT>

[ Voor 12% gewijzigd door StevenK op 14-06-2006 14:15 ]

Was advocaat maar vindt het juridische nog steeds leuk. Doet tegenwoordig iets in de metaal.


  • markjuh
  • Registratie: Juli 2000
  • Laatst online: 16-11-2025
If InStr(1, strMessage, "X-Spam-Level: *****", 1) Then

Dit gedeelte kan ik dus gebruiken. Alleen wil ik het in een public folder gooien. pffff.... Nog een idee hoe ik dit doe?

Sowieso is je script nogal omslachtig omdat alles in een dir wordt geflikkerd, vervolgens gechecked en dan weer terug. is leuklas je 10 mailboxen hebt maar deze omgeving is toch wat te groot. Ik ben bang dat de boel ernstig langzaam wordt hiermee.

[ Voor 43% gewijzigd door markjuh op 14-06-2006 14:33 ]


  • StevenK
  • Registratie: Februari 2001
  • Laatst online: 18-02 20:39
Markjuh schreef op woensdag 14 juni 2006 @ 14:23:
If InStr(1, strMessage, "X-Spam-Level: *****", 1) Then

Dit gedeelte kan ik dus gebruiken. Alleen wil ik het in een public folder gooien. pffff.... Nog een idee hoe ik dit doe?
Ik zou de recipient vervangen of beter nog het hele bericht als attachment naar die public folder gooien.

Op de link die ik hierboven gaf, staan ook verwijzingen naar o.a. de MS documentatie en andere meuk die interessant is voor dit gedoe.

[ Voor 30% gewijzigd door StevenK op 14-06-2006 14:38 ]

Was advocaat maar vindt het juridische nog steeds leuk. Doet tegenwoordig iets in de metaal.


  • markjuh
  • Registratie: Juli 2000
  • Laatst online: 16-11-2025
ok, ik heb nu dit:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<SCRIPT LANGUAGE="VBScript"> 

Sub IEventIsCacheable_IsCacheable() 
    'To implement the interface, and return S_OK implicitly 
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus) 
    Dim envFlds 
    Dim Spam 
    Dim strMessage
    Set envFlds = Msg.EnvelopeFields 
    Spam = InStr(1, strMessage, "X-Spam-Level: ****", 1) 

    If Spam > 0 Then 
        'Do not deliver, place message in the Badmail directory. 
        envFlds ("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus") = 3 
        envFlds.Update  'Commit the changes of the message status 'Skip remain event sinks 
        EventStatus = 1
    End If 
End Sub 

</SCRIPT>
[/quote]

Aangezien ik niet zo'n code/programmeer wonder ben hoop ik dat je me nog iets voort kunt helpen. Ik zou nu denken dat, indien spam, mail verplaatst wordt naar de badmail directory. Natuurlijk gebeurt dit niet omdat ik het fout doe. Zou je me nog voort kunnen helpen?

  • Equator
  • Registratie: April 2001
  • Laatst online: 16:59

Equator

Crew Council

#whisky #barista

Markjuh schreef op woensdag 14 juni 2006 @ 14:55:
ok, ik heb nu dit:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<SCRIPT LANGUAGE="VBScript"> 

Sub IEventIsCacheable_IsCacheable() 
    'To implement the interface, and return S_OK implicitly 
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus) 
    Dim envFlds 
    Dim Spam 
    Dim strMessage
    Set envFlds = Msg.EnvelopeFields 
    Spam = InStr(1, strMessage, "X-Spam-Level: ****", 1) 

    If Spam > 0 Then 
        'Do not deliver, place message in the Badmail directory. 
        envFlds ("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus") = 3 
        envFlds.Update  'Commit the changes of the message status 'Skip remain event sinks 
        EventStatus = 1
    End If 
End Sub 

</SCRIPT>


Aangezien ik niet zo'n code/programmeer wonder ben hoop ik dat je me nog iets voort kunt helpen. Ik zou nu denken dat, indien spam, mail verplaatst wordt naar de badmail directory. Natuurlijk gebeurt dit niet omdat ik het fout doe. Zou je me nog voort kunnen helpen?
Je dimensioneert de variabele strMessage, maar die vul je niet.
Je zal de header / subject van Msg moeten controleren.

Dus iets als
Visual Basic:
1
Spam = InStr(Msg.Subject, "X-Spam-Level: ****")

(De eerste "start" en de laatste "Compare" argumenten zijn optioneel. Die heb je niet nodig hier.)
Zie ook: http://www.devguru.com/Te...cript/quickref/instr.html

Letop, ik weet niet of Msg.Subject inderdaad het subject is van het bericht. Dat kan je vast wel vinden wat dat moet zijn..

[ Voor 9% gewijzigd door Equator op 14-06-2006 15:42 ]


  • Koffie
  • Registratie: Augustus 2000
  • Laatst online: 14:37

Koffie

Koffiebierbrouwer

Braaimeneer

Sorry hoor, maar er is nu gegnoeg info gegeven, wij gaan hier niet jou commerciele spam script zitten ontwikkelen omdat je niet weet waarmee je bezig bent.

Tijd voor een nieuwe sig..

Pagina: 1

Dit topic is gesloten.