C# 自动登录DiscuzNT论坛并发帖

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Web;

namespace Malicious
{
    public partial class Form1 : Form
    {
        private readonly string BBSURL = "http://bbs.XXXXX.com";
        private readonly string USERNAME = "Malicious";
        private readonly string PASSWORD = "123456";

        private CookieCollection gCookieCollention = null;
        private HttpWebRequest BBSRequest = null;
        private HttpWebResponse BBSResponse = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void startBtn_Click(object sender, EventArgs e)
        {
            string loginUrl = string.Format("{0}/login.aspx ", BBSURL);
            RemoveCookies();
            MaliciousLogin(loginUrl, USERNAME, PASSWORD);
            startBtn.Enabled = false;
        }
        /// <summary>
        /// 自动登录
        /// </summary>
        public void MaliciousLogin(string loginUrl, string usr, string pwd)
        {
            string responseHTML = string.Empty; ;
            string loginstr = string.Format("username={0}&password={1}&question=0&answer=&expires=43200&templateid=0&login=%E7%99%BB%E5%BD%95", usr, pwd);
            loginstr = EncodePost(loginstr);
            byte[] replybyte = Encoding.UTF8.GetBytes(loginstr);

            try
            {
                CookieContainer _cookieContainer = new CookieContainer();
                BBSRequest = (HttpWebRequest)WebRequest.Create(loginUrl);
                BBSRequest.CookieContainer = _cookieContainer;
                BBSRequest.ContentType = "application/x-www-form-urlencoded";
                BBSRequest.Method = "POST";
                //post 开始
                BBSRequest.ContentLength = replybyte.Length;
                Stream newStream = BBSRequest.GetRequestStream();
                newStream.Write(replybyte, 0, replybyte.Length);
                newStream.Close();
                //post 结束

                //返回HTML
                BBSResponse = (HttpWebResponse)BBSRequest.GetResponse();
                Stream dataStream = BBSResponse.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"));
                responseHTML = reader.ReadToEnd();

 

                gCookieCollention = BBSResponse.Cookies;
                if (responseHTML.IndexOf("登录成功") > 0)
                    MessageBox.Show("Login successful");
                else
                    MessageBox.Show(responseHTML);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }


        }
        /// <summary>
        /// post 帖子
        /// </summary>
        private void PostTopic(string forumid, string title, string content)
        {

            try
            {
                BBSRequest = (HttpWebRequest)WebRequest.Create(string.Format("{0}/posttopic.aspx?forumid={1}", BBSURL,forumid));
                BBSRequest.ContentType = "application/x-www-form-urlencoded";
                BBSRequest.Method = "POST";
                BBSRequest.Referer = string.Format("{0}/posttopic.aspx?forumid={1}", BBSURL, forumid);
                BBSRequest.KeepAlive = true;
                BBSRequest.AllowWriteStreamBuffering = false;
                BBSRequest.ContentType = "multipart/form-data; boundary=---------------------------7d8182810472";

                CookieContainer cookieCon = new CookieContainer();
                BBSRequest.CookieContainer = cookieCon;
                BBSRequest.CookieContainer.Add(gCookieCollention);


                string topicStr = BuildPostContent(title, content);

                // string topic = EncodePost(topicStr);
                string topic = topicStr;

                byte[] replybyte = Encoding.UTF8.GetBytes(topic);
                BBSRequest.ContentLength = replybyte.Length;
                Stream newStream = BBSRequest.GetRequestStream();
                newStream.Write(replybyte, 0, replybyte.Length);
                newStream.Close();

                // get response
                BBSResponse = (HttpWebResponse)BBSRequest.GetResponse();
                Stream dataStream = BBSResponse.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"));
                string responseHTML = reader.ReadToEnd();

                reader.Close();
                dataStream.Close();
                BBSResponse.Close();
                if (responseHTML.IndexOf("发表主题成功") > 0)
                    MessageBox.Show("发表主题成功!");
                else
                    MessageBox.Show(responseHTML);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private string BuildPostContent(string title, string message)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"temppassword/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"question/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"answer/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"title/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(title + "/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"iconid/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"usesig/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("1/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"posteditor_mediatyperadio/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("on/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"message/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(message + "/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"sposteditor_mode/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"restoredata/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("恢复数据/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"previewbutton/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("预览帖子/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"postfile/"; filename=/"/"/r/n");
            sb.Append("Content-Type: application/octet-stream/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"localid/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"readperm/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"attachdesc/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"albums/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"postfile/"; filename=/"/"/r/n");
            sb.Append("Content-Type: application/octet-stream/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"localid/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("1/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"readperm/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"attachdesc/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"albums/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"topicreadperm/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append(BoundaryString);
            sb.Append("Content-Disposition: form-data; name=/"postbytopictype/"/r/n");
            sb.Append(Environment.NewLine);
            sb.Append("0/r/n");
            sb.Append("-----------------------------7d8182810472--");
            sb.Append(Environment.NewLine);
            return sb.ToString();
        }
        private string BoundaryString
        {
            get { return "-----------------------------7d8182810472/r/n"; }
        }
        private string EncodePost(string input)
        {
            string output = null;
            Char[] reserved = { '?', '=', '&' };
            if (input != null)
            {
                int i = 0, j;
                while (i < input.Length)
                {
                    j = input.IndexOfAny(reserved, i);
                    if (j == -1)
                    {
                        output = output + HttpUtility.UrlEncode(input.Substring(i, input.Length - i), System.Text.Encoding.GetEncoding("utf-8"));
                        break;
                    }
                    string tt = HttpUtility.UrlEncode(input.Substring(i, j - i), System.Text.Encoding.GetEncoding("utf-8"));
                    output += tt;
                    output += input.Substring(j, 1);
                    i = j + 1;
                }
                return output;
            }
            else
                return null;
        }

        private void btnPost_Click(object sender, EventArgs e)
        {
            string forumid = txtForumID.Text.Trim();
            string title = txtTitle.Text.Trim();
            string content = txtContent.Text.Trim();
            PostTopic(forumid, title, content);
        }
        private void RemoveCookies()
        {
            int cookiesmax = Environment.GetFolderPath(Environment.SpecialFolder.Cookies).Length;
            for (int i = 0; i < cookiesmax; i++)
                Environment.GetFolderPath(Environment.SpecialFolder.Cookies).Remove(0);
        }
    }
}

易语言Discuz类型论坛登陆取用户信息-易语言 易语言Discuz类型论坛登陆取用户信息 立即下载

相关推荐

ASP.NET 小型BBS论坛c#版)

小型BBS论坛,主要功能都有,带数据库文件,结构清晰明朗~VS2005+SQL SERVER 2005

C#实现Discuz登录程序

加载HttpHelper.cs类 using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO; using System.Text.RegularExpressions; using System.IO.Compression; using System.Se

CUIroot的博客 3546

一个基于C#+ASP.NET实现的DotBBSV1.1.0轻量、安全、易扩展论坛源码

一个基于C#+ASP.NET实现的DotBBSV1.1.0轻量、安全、易扩展论坛源码。

C#简易论坛BBS

论坛系统是基于是VS 2008+SQL Server 2005实现的,它具有使用方便、操作灵活、运行稳定、安全可靠等特点。 (1)系统前台功能:查看自己发表的帖子、查看帖子摘要、用户注册、用户登录、发表帖子、回复帖子。 (2)系统后台功能:用户信息管理、用户注册、用户权限管理。 压缩包带三个文档 概要设计说明书 软件需求说明书 数据库设计说明书

C#自动登录DiscuzNT论坛发帖

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Net;using S

vrix的专栏 3102

C# bbs 应用实例

C#BBS应用实例下载。应该是挺好的。对于asp.net有一定的帮助。

asp.net(C#) BBS论坛)程序源码 for vs2008

一套非常不错的论坛程序! 1、安装环境:Windows2000+IIS5或Windows2003+IIS6或WinXP+IIS5,.NET Framework 2.0,Sql版本需安装SQL Server2000,安装前请确保您满足安装环境。   2、下载论坛:动网论坛每次发布最新版本论坛,都会第一时间公布于动网先锋(www.dvbbs.net),另外您也可以通过访问动网论坛的动态更新页面(asp.dvbbs.net/download.asp)随时了解动网论坛的最新情况。   3、解压和安装论坛:     1). 本地调试将论坛压缩包解压到IIS对应的网站目录(如C:\inetpub\wwwroot\bbs),网络调试将解压出来的所有文件通过FTP上传到您的主页空间(如上传到空间中的bbs目录),如果您是独立服务器可参照本地调试的方式进行安装。     2). 动网论坛安装无需繁复的过程,只需运行http://localhost(或域名)/论坛目录名/install/install.html按提示操作即可完成安装。安装完成后本地预览通常用http://localhost/论坛目录名/index.aspx访问,网络调试预览通常用http://域名/论坛目录名/index.aspx访问。   4、论坛的配置和调试:     1). 默认管理帐号:用户名:admin,密码:admin888     2). 使用默认管理帐号登录论坛,动网论坛出于安全方面考虑,前后台密码可设置为不同,默认前后台帐号是相同的,建议您登录后对默认的帐号进行修改操作。管理员用管理员帐号登录后,在顶部的导航菜单中可看到管理链接。前台帐号可在用户控制面板中修改,后台管理帐号可在后台的管理员管理中修改。     3). 更改数据库文件名,参考 论坛安全设置 中说明。   5、详细的论坛配置可参考更详细的帮助说明。   6、为了保证您论坛的安全性,建议您仔细阅读论坛安全说明部分。

ASP.NET BBS系统 源码

ASP.NET BBS系统 源码 包含数据库

C#dz论坛发帖机Post发帖机源码

C#dz论坛发帖机Post发帖机源码成品取消下载,留源码大家。因为有的论坛版本不同,得到的cookie也不同,这个版本只能原版3.2才能获取,所以取消成品了。软件支持多账号登录发帖。 至于多标题多内容,请各位自行研究,我已经把多账号导入的代码写了 那么导入标题跟内容,你们自己动动手还能搞不定?别的dz论坛类型软件自行看源码修改

C#自动发帖程序 完整项目,C#源代码

C#自动发帖程序 完整项目,C#源代码,以魅族论坛为例进行发帖,已测试。账户(mychange)当前帖子数4700+。

delphi 编写的discuz 自动发贴、discuz 自动回帖、discuz 自动顶贴软件 修复所有bug

自己编写的方便大家灌水和发广告贴、顶贴使自己的帖子不沉的好东西,discuz 所有版本通吃!

C#模拟登录Discuz论坛 附代码 Discuz X1.5

C#模拟登录Discuz论坛 附代码 Discuz X1.5 本方法通过将账号和密码提交到登录页面,返回一个CookieContainer类型的COOKIE容器,需要模拟登录访问的时候带着这个CookieContainer访问指定地址便可。

子曰 4716

前端开发的45个经典技巧

1、首次给变量赋值是切记使用var关键字(闲谈:清楚的记得有次去面试前端,一个项目经理同时面我和另外一个人,面试官开始就是要我们俩手写一个数组去重函数,哗哗的一下写完交了,面试官看来下之后直接给了一旁的竞争对手,叫她给我指出我代码的错误,才知道刚才忘记写var声明变量,瞬间脸红走了)=。=~~ 回归正题:变量没有声明直接赋值的话,默认会作为一个全局变量(一切无主的都是window的),要尽量避免

u013084331的博客 7003

基于asp.net的简单的BBS论坛管理系统源码

1.主要功能这个系统是比较简单的 BBS论坛管理系统源码,包含以下几个功能,用户注册登陆、发表论坛、主题分类、帖子评论、发帖等等模块。2.开发工具及其环境系统采用asp . net的webform框架,开发语言为c#,开发工具为 VS2013 ,数据库为SQLserver数据库,版本不限制,任何版本都可以。3.系统详情图4.下载链接源码下载链接:https://pan.quark.cn/s/b63a1dc155a45.写在最后点个关注哈!

vx_ws106236019的博客 855

C#基于ASP.NET的社区人口管理系统

社区人口信息管理系统,是一个社区内部提供信息管理的平台,是完全的,高速的,开放的,其核心思想是提供一个以自然语言为主的用户界面,让用户能够更好的刚加方便快捷的管理物流信息的一个渠道和平台。该系统的基本功能包括用户登录,管理员信息管理,常住人口管理,迁出人口信息管理,迁入人口信息管理,查询统计,员工信息管理,修改密码等功能。该系统的基本功能包括用户登录,用户登录,管理员信息管理,常住人口管理,迁出人口信息管理,迁入人口信息管理,查询统计,员工信息管理,修改密码等功能。会员信息:包括会员注册登录和留言等。

QQ55318293的博客 1021

我的论坛源代码(十)

<!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--><script type="text/javascript"

zgqtxwd的专栏 2387
上一篇: [讨论]一个真正的IT人来谈中国与印度的软件
HIGLC
博客等级 码龄17年 8粉丝 7原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值