Malware Analysis
AltChunk 클래스를 이용한 OOXML 문서 안에 OOXML 문서 삽입
Forgotten One
2021. 2. 5. 11:14
두 문서를 하나로 통합할 때 사용할 수 있는 코드가 해당 링크에 나와있다.
AltChunk Class (DocumentFormat.OpenXml.Wordprocessing)
Defines the AltChunk Class. When the object is serialized out as xml, its qualified name is w:altChunk.
docs.microsoft.com
해당 코드는 docx file 안에 docx file을 넣지만 조금만 변형하면 rtf 파일을 넣는 코드로도 변경할 수 있다.
using System.Linq;
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace altChunk
{
class Program
{
static void Main(string[] args)
{
string fileName1 = @"c:\Users\Public\Documents\Destination.docx";
string fileName2 = @"c:\Users\Public\Documents\Source.docx";
string testFile = @"c:\Users\Public\Documents\Test.docx";
File.Delete(fileName1);
File.Copy(testFile, fileName1);
using (WordprocessingDocument myDoc =
WordprocessingDocument.Open(fileName1, true))
{
string altChunkId = "AltChunkId1";
MainDocumentPart mainPart = myDoc.MainDocumentPart;
AlternativeFormatImportPart chunk =
mainPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.WordprocessingML, altChunkId);
using (FileStream fileStream = File.Open(fileName2, FileMode.Open))
chunk.FeedData(fileStream);
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
mainPart.Document
.Body
.InsertAfter(altChunk, mainPart.Document.Body
.Elements<Paragraph>().Last());
mainPart.Document.Save();
}
}
}
}
문제는 어떤 취약점을 악용한 파일을 따로 숨기는 형태로도 해당 코드를 악용할 수 있다는 것이다.
나중에 따로 샘플을 만들어서 어떻게 분석해야하는 지 알아봐야겠다.